5👍
Found out what the problem was. We were also using django-cacheops
and the response was hitting the cache instead of running the query again. The irony is I had already thought the problem could be cache related but my attempt of disabling it failed and misled me into ruling it out as the cause of the problem. Eventually we figured out how to properly disable it.
Here’s a way you can disable caching for tests if you’re using cacheops and py.test:
from cacheops import invalidate_all
@pytest.fixture(scope='function', autouse=True)
def invalidate_cache():
invalidate_all()
1👍
pytest-django indeed isolate tests from each other by reverting transaction at the end of each test.
If you want to make sure your database doesn’t have any Station before the test add at the beginning of test_no_stations
:
assert not Station.objects.all().exist()
If this is proven wrong, either you missed something in your pytest configuration either the issue is on your code.
- [Django]-Show management commands in admin site
- [Django]-Import modules that are above project root
- [Django]-Django Edit Form Data: data is duplicated instead of being updated