Replies: 2 comments 2 replies
-
This isn't an issue in pytest:
I'm converting this to a discussion. |
Beta Was this translation helpful? Give feedback.
0 replies
-
This would happen the same way with import sys
from unittest.mock import patch
with patch("random.randint", return_value=4):
if 'C' in sys.modules:
del sys.modules['C']
from mocked_import.prod import C
def test_uses_randint():
assert C().value == 4 You may have to do the same for the other test. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
pip list
from the virtual environment you are usingProduction code in prod.py:
Verify production code randomness:
Setup:
test_unmocked.py:
test_mocked.py:
Actual breakage:
Basically, by running test_unmocked.py first test_mocked.py gets an unmocked
randint
. That is, the mocking in test_mocked.py has no effect.Detected because it caused a test without any mocks to fail with an error message mentioning mocks after working around a pynamodb issue where I can't change a field to be a
@property
.Beta Was this translation helpful? Give feedback.
All reactions