I have a class which has a side effect at import time: it populates a field with a value from a deployed infrastructure. It basically boils down to this:
class MyModel:
class Meta:
table_name = get_param("table_name")
I want to use instances of MyModel
in offline tests, so I need to make sure that boto3 doesn't actually run the production get_param
code. I've done it by mocking out get_param
in these tests:
with patch("….get_param"):
from … import MyModel
def test_…
Clunky, but it sort of works. The problem is that if I run pytest
with this test file first and then an acceptance test file (which does need to use the real get_param
), the acceptance test ends up with a mocked version of get_param
(reversing the file sequence makes both tests pass). The acceptance test runs fine on its own, but I'd rather not pull apart the test suite based on such a weird premise. Is there some way to avoid this namespace pollution?