You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[3.13.0] New logged calls in MagicMock mock_calls attribute #420
I ran into a possibly related issue that happens in 3.13.0 but not 3.12.0: mocker.patch.object doesn't seem to fully reset between tests, leading to patches bleeding into unrelated tests AFAICT - at least in certain cases.
I don't have much detail to add about this at the moment but maybe it's at least a clue.
def test2():
> assert Class2.get() == 2
E assert 3 == 2
E + where 3 = <function test1.<locals>.handle_get at 0x101950900>()
E + where <function test1.<locals>.handle_get at 0x101950900> = Class2.get
test_thing.py:22: AssertionError
It fails intermittently, so you may need to run it a few times to reproduce the issue. Oddly enough, it only seems to happen when doing two patches: if you try commenting out either patch in the first test, then the test seems to succeed 100% of the time. Very strange.
(Python 3.11.4)
Note: I'm not sure if this is related to the original issue that @ofx53 reported, but seems coincident anyways.
I suspected the cause of the problem, but was not able to reproduce because it was working when installed in normal methods, but using staticmethod triggered the problem!
For anyone looking for a temporary fix until the new release is out, just add ,!=3.13.0 to your version specifier of pytest-mock, something like pytest-mock~=3.12,!=3.13.0 or pytest-mock = "^3.12.0,!=3.13.0" depending on your packaging tool
@nicoddemus it'd be good if 3.13.0 were also yanked from PyPI
@nicoddemus it'd be good if 3.13.0 were also yanked from PyPI
In general I understand, but we recently yanked pytest from PyPI and the result was not good, it breaks some workflows (which IMO are not correct anyway, but still).
Activity
kkroening commentedon Mar 21, 2024
I ran into a possibly related issue that happens in 3.13.0 but not 3.12.0:
mocker.patch.objectdoesn't seem to fully reset between tests, leading to patches bleeding into unrelated tests AFAICT - at least in certain cases.I don't have much detail to add about this at the moment but maybe it's at least a clue.
nicoddemus commentedon Mar 21, 2024
Hmm seems like an unintended regression.
I have not been able to reproduce the issue however. Any chance of someone providing a MWE? I would be happy to fix it then and make a new release.
kkroening commentedon Mar 21, 2024
Here's an isolated example:
Output:
It fails intermittently, so you may need to run it a few times to reproduce the issue. Oddly enough, it only seems to happen when doing two patches: if you try commenting out either patch in the first test, then the test seems to succeed 100% of the time. Very strange.
(Python 3.11.4)
Note: I'm not sure if this is related to the original issue that @ofx53 reported, but seems coincident anyways.
nicoddemus commentedon Mar 21, 2024
Thanks @kkroening!
I suspected the cause of the problem, but was not able to reproduce because it was working when installed in normal methods, but using staticmethod triggered the problem!
I will make a new release shortly. 👍
rkechols commentedon Mar 21, 2024
I've also run into a problem with
pytest-mock==3.13.0Using kkroening's minimal example, this env runs into the bug:
$ python --version Python 3.10.13 $ pip freeze | grep pytest pytest==7.4.4 pytest-base-url==2.1.0 pytest-cov==3.0.0 pytest-mock==3.13.0This environment works fine on the given example:
$ python --version Python 3.10.13 $ pip freeze | grep pytest pytest==7.4.4 pytest-base-url==2.1.0 pytest-cov==3.0.0 pytest-mock==3.12.0For anyone looking for a temporary fix until the new release is out, just add
,!=3.13.0to your version specifier ofpytest-mock, something likepytest-mock~=3.12,!=3.13.0orpytest-mock = "^3.12.0,!=3.13.0"depending on your packaging tool@nicoddemus it'd be good if
3.13.0were also yanked from PyPIFix regression with mocker.patch not being undone correctly
nicoddemus commentedon Mar 21, 2024
In general I understand, but we recently yanked pytest from PyPI and the result was not good, it breaks some workflows (which IMO are not correct anyway, but still).
I'm preparing a new release right now.
nicoddemus commentedon Mar 21, 2024
Release 3.14 is out, thanks everyone for the help, and sorry for the regression!
Update dependency pytest-mock to v3.14.0 (#67)
Bump pytest-mock from 3.12.0 to 3.14.0 (#336)
Bump pytest-mock from 3.12.0 to 3.14.0 (#8238)
chore: pip: Bump pytest-mock from 3.12.0 to 3.14.0 (#491)
Update dependency pytest-mock to v3.14.0 (#70)
Update dependency pytest-mock to v3.14.0 (#391)
31 remaining items
Update pytest-mock requirement from >=3.0 to >=3.15.1 (#2)
chore(deps): bump pytest-mock from 3.12.0 to 3.15.1 in /swipesavvy-ai…
chore(deps-dev): update pytest-mock requirement from >=3.0.0 to >=3.1…
Update pytest-mock requirement from ~=3.14.0 to ~=3.15.1 (vllm-projec…
🐛 fix(deps): update pytest-mock requirement from >=3.11.0 to >=3.15.1 (…
build(deps): update pytest-mock requirement from >=3.12 to >=3.15.1 i…
chore(deps-dev): bump the python-dev-tools group across 1 directory w…
[pip] update pytest-mock requirement from >=3.14.0 to >=3.15.1 in the…
[pip] bump the testing group with 2 updates (#196)
chore(deps-dev): update pytest-mock requirement from >=3.14 to >=3.15…
build(deps-dev): update pytest-mock requirement from ~=3.15.1 to ~=3.…
chore(deps-dev): update pytest-mock requirement from >=3.15.1 to >=3.…
chore(deps-dev): update pytest-mock requirement from >=3.15.1 to >=3.…
build(deps): bump the pip group with 6 updates (#127)
chore(deps-dev): update pytest-mock requirement from ^3.15.1 to ^3.16…