Open feuloren opened 8 years ago
I've got same issue simply by simply running my old tests with pytest runner.
same issue here with a simple test:
class TestFeatureViewSet():
def test_get_dataset_without_dataset_pk_raises_404(self, mocker):
viewset = FeatureViewSet()
viewset.kwargs = {
'dataset_pk': 1
}
with pytest.raises(exceptions.NotFound):
viewset.get_dataset()
def test_get_dataset_calls_dataset_manager(self, mocker):
get_call = mocker.patch.object(
Dataset.objects,
'get',
return_value='foo'
)
viewset = FeatureViewSet()
viewset.kwargs = {
'dataset_pk': 1
}
dataset = viewset.get_dataset()
assert get_call.called_with(dataset_pk=1)
assert dataset is not None
@pytest.mark.django_db(transactional=True)
def test_get_dataset_without_dataset_pk_raises_404t_existing_dataset(self):
dataset = Dataset.objects.all()
This fails with transactional=True
and without.
@george-silva How does it fail? With "Database access not allowed, use the "django_db" mark to enable it."?
Can you provide an example that can be run standalone (in pytest-django's test suite)?
Getting the same issue when working with db within the post_migrate
receiver.
I am trying to test a view that uses a transaction but the test fails with "Failed: Database access not allowed, use the "django_db" mark to enable it." Here is my test code
Here is the full output:
I'm using django 1.9, pytest 2.8 and postgresql 9.5 Do you know what the problem is ? I made sure to follow the documentation.