How do I prevent fixtures from conflicting with django post_save signal code?

I think I figured out a way to do this. There is a ‘raw’ parameter in the kwargs passed in along with signals so I can replace my test above with this one: if (kwargs.get(‘created’, True) and not kwargs.get(‘raw’, False)): Raw is used when loaddata is running. This seems to do the trick. It is … Read more

@Patch decorator is not compatible with pytest fixture

When using pytest fixture with mock.patch, test parameter order is crucial. If you place a fixture parameter before a mocked one: from unittest import mock @mock.patch(‘my.module.my.class’) def test_my_code(my_fixture, mocked_class): then the mock object will be in my_fixture and mocked_class will be search as a fixture: fixture ‘mocked_class’ not found But, if you reverse the order, … Read more

Problems with contenttypes when loading a fixture in Django

manage.py dumpdata –natural will use a more durable representation of foreign keys. In django they are called “natural keys”. For example: Permission.codename is used in favour of Permission.id User.username is used in favour of User.id Read more: natural keys section in “serializing django objects” Some other useful arguments for dumpdata: –indent=4 make it human readable. … Read more

Pass a parameter to a fixture function

This is actually supported natively in py.test via indirect parametrization. In your case, you would have: @pytest.fixture def tester(request): “””Create tester object””” return MyTester(request.param) class TestIt: @pytest.mark.parametrize(‘tester’, [[‘var1’, ‘var2’]], indirect=True) def test_tc1(self, tester): tester.dothis() assert 1

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)