{"action":"created","issue":{"url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/342","repository_url":"https://api.github.com/repos/pytest-dev/pytest-django","labels_url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/342/labels{/name}","comments_url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/342/comments","events_url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/342/events","html_url":"https://github.com/pytest-dev/pytest-django/issues/342","id":160703724,"number":342,"title":"testing with django's mirroring db","user":{"login":"stavinsky","id":4471309,"avatar_url":"https://avatars.githubusercontent.com/u/4471309?v=3","gravatar_id":"","url":"https://api.github.com/users/stavinsky","html_url":"https://github.com/stavinsky","followers_url":"https://api.github.com/users/stavinsky/followers","following_url":"https://api.github.com/users/stavinsky/following{/other_user}","gists_url":"https://api.github.com/users/stavinsky/gists{/gist_id}","starred_url":"https://api.github.com/users/stavinsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stavinsky/subscriptions","organizations_url":"https://api.github.com/users/stavinsky/orgs","repos_url":"https://api.github.com/users/stavinsky/repos","events_url":"https://api.github.com/users/stavinsky/events{/privacy}","received_events_url":"https://api.github.com/users/stavinsky/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-06-16T16:25:12Z","updated_at":"2016-07-15T15:32:43Z","closed_at":null,"body":"Hello. \r\nIs any way to use Django's mirror db function like [here](https://docs.djangoproject.com/en/1.9/topics/testing/advanced/#tests-and-multiple-databases)?"},"comment":{"url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/comments/232985575","html_url":"https://github.com/pytest-dev/pytest-django/issues/342#issuecomment-232985575","issue_url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/342","id":232985575,"user":{"login":"blueyed","id":9766,"avatar_url":"https://avatars.githubusercontent.com/u/9766?v=3","gravatar_id":"","url":"https://api.github.com/users/blueyed","html_url":"https://github.com/blueyed","followers_url":"https://api.github.com/users/blueyed/followers","following_url":"https://api.github.com/users/blueyed/following{/other_user}","gists_url":"https://api.github.com/users/blueyed/gists{/gist_id}","starred_url":"https://api.github.com/users/blueyed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blueyed/subscriptions","organizations_url":"https://api.github.com/users/blueyed/orgs","repos_url":"https://api.github.com/users/blueyed/repos","events_url":"https://api.github.com/users/blueyed/events{/privacy}","received_events_url":"https://api.github.com/users/blueyed/received_events","type":"User","site_admin":false},"created_at":"2016-07-15T15:32:43Z","updated_at":"2016-07-15T15:32:43Z","body":"I don't think so.\r\nSee \"Tests requiring multiple databases\" in `docs/database.rst`.\r\n\r\n@pelme \r\nI think for this we should provide a fixture that can be overwritten and wraps the Django TestCase class?\r\n\r\nDjango uses this `_database_names` method: https://github.com/django/django/blob/ab2f5f764a2f6db97e23cccd5c4f5abbb43d1caf/django/test/testcases.py#L869-L877\r\n\r\nI have tried the following:\r\n```python\r\n@pytest.fixture\r\ndef use_multidb_for_django_testcases(monkeypatch):\r\n    monkeypatch.setattr('django.test.TransactionTestCase.multi_db', True,\r\n                        raising=False)\r\n\r\n\r\n@pytest.fixture\r\ndef django_multidb(use_multidb_for_django_testcases, db):\r\n    return db\r\n\r\n\r\ndef test_foo(django_multidb, …):\r\n```\r\n\r\nWith `--reuse-db` I am getting this error on teardown:\r\n\r\n```\r\n..…/Vcs/django/django/test/testcases.py:924: in _post_teardown\r\n    self._fixture_teardown()\r\n..…/Vcs/django/django/test/testcases.py:1078: in _fixture_teardown\r\n    self._rollback_atomics(self.atomics)\r\n..…/Vcs/django/django/test/testcases.py:1020: in _rollback_atomics\r\n    transaction.set_rollback(True, using=db_name)\r\n..…/Vcs/django/django/db/transaction.py:103: in set_rollback\r\n    return get_connection(using).set_rollback(rollback)\r\n..…/Vcs/django/django/db/backends/base/base.py:415: in set_rollback\r\n    \"The rollback flag doesn't work outside of an 'atomic' block.\")\r\nE   django.db.transaction.TransactionManagementError: The rollback flag doesn't work outside of an 'atomic' block.\r\n```\r\n\r\nWith `--create-db` it results in:\r\n```\r\nPASSED\r\nproject/app/tests/test_models.py::test_db_router ERRORDestroying test database for alias 'replica' ('test_project')...\r\nTraceback (most recent call last):\r\n  File \"…/Vcs/django/django/db/backends/utils.py\", line 62, in execute\r\n    return self.cursor.execute(sql)\r\npsycopg2.OperationalError: database \"test_project\" is being accessed by other users\r\nDETAIL:  There is 1 other session using the database.\r\n```\r\n```\r\n"}}
{"actor":{"display_login":"blueyed"}}