{"action":"created","issue":{"url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/396","repository_url":"https://api.github.com/repos/pytest-dev/pytest-django","labels_url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/396/labels{/name}","comments_url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/396/comments","events_url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/396/events","html_url":"https://github.com/pytest-dev/pytest-django/issues/396","id":178095044,"node_id":"MDU6SXNzdWUxNzgwOTUwNDQ=","number":396,"title":"How to allow database access globally without using django_db marks?","user":{"login":"arne-cl","id":994109,"node_id":"MDQ6VXNlcjk5NDEwOQ==","avatar_url":"https://avatars1.githubusercontent.com/u/994109?v=4","gravatar_id":"","url":"https://api.github.com/users/arne-cl","html_url":"https://github.com/arne-cl","followers_url":"https://api.github.com/users/arne-cl/followers","following_url":"https://api.github.com/users/arne-cl/following{/other_user}","gists_url":"https://api.github.com/users/arne-cl/gists{/gist_id}","starred_url":"https://api.github.com/users/arne-cl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arne-cl/subscriptions","organizations_url":"https://api.github.com/users/arne-cl/orgs","repos_url":"https://api.github.com/users/arne-cl/repos","events_url":"https://api.github.com/users/arne-cl/events{/privacy}","received_events_url":"https://api.github.com/users/arne-cl/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-09-20T15:33:06Z","updated_at":"2018-05-31T08:01:20Z","closed_at":"2016-11-12T10:16:07Z","author_association":"NONE","body":"I am struggling to convert my Django test runner based tests to pytest. \nI would expect that putting\n\n```\nimport pytest\npytestmark = pytest.mark.django_db\n```\n\ninto the last module of the stacktrace that belongs to my code (lib/frontend/decorators.py)\nwould mitigate this, but it didn't. Putting it into all four of my modules on the stacktrace didn't help either.\n\nIs there any way I can globally allow database access in pytest-django?\n\n```\nvagrant@vagrant-ubuntu-trusty-64:/vagrant$ pytest \n== test session starts ==\nplatform linux2 -- Python 2.7.6, pytest-3.0.2, py-1.4.31, pluggy-0.3.1\nDjango settings: patient.settings (from ini file)\nrootdir: /vagrant, inifile: pytest.ini\nplugins: django-3.0.0, pythonpath-0.7.1\ncollected 265 items / 2 errors \n\n[...]\n\n_ ERROR collecting lib/tests/report/testfunc.py _\nlib/tests/report/testfunc.py:6: in <module>\n    from report.func import generate_report_filename\nlib/report/func.py:29: in <module>\n    from frontend import chart\nlib/frontend/chart.py:294: in <module>\n    @pytest.mark.django_db\nlib/frontend/decorators.py:20: in decorator\n    if Site.objects.get_current().id in (allowed_site_ids):\n/usr/local/lib/python2.7/dist-packages/django/contrib/sites/models.py:60: in get_current\n    return self._get_site_by_id(site_id)\n/usr/local/lib/python2.7/dist-packages/django/contrib/sites/models.py:39: in _get_site_by_id\n    site = self.get(pk=site_id)\n/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py:127: in manager_method\n    return getattr(self.get_queryset(), name)(*args, **kwargs)\n/usr/local/lib/python2.7/dist-packages/django/db/models/query.py:328: in get\n    num = len(clone)\n/usr/local/lib/python2.7/dist-packages/django/db/models/query.py:144: in __len__\n    self._fetch_all()\n/usr/local/lib/python2.7/dist-packages/django/db/models/query.py:965: in _fetch_all\n    self._result_cache = list(self.iterator())\n/usr/local/lib/python2.7/dist-packages/django/db/models/query.py:238: in iterator\n    results = compiler.execute_sql()\n/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py:838: in execute_sql\n    cursor = self.connection.cursor()\n/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py:162: in cursor\n    cursor = self.make_debug_cursor(self._cursor())\n/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py:135: in _cursor\n    self.ensure_connection()\nE   Failed: Database access not allowed, use the \"django_db\" mark to enable it.\n```\n"},"comment":{"url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/comments/393445430","html_url":"https://github.com/pytest-dev/pytest-django/issues/396#issuecomment-393445430","issue_url":"https://api.github.com/repos/pytest-dev/pytest-django/issues/396","id":393445430,"node_id":"MDEyOklzc3VlQ29tbWVudDM5MzQ0NTQzMA==","user":{"login":"lmannering","id":14155046,"node_id":"MDQ6VXNlcjE0MTU1MDQ2","avatar_url":"https://avatars2.githubusercontent.com/u/14155046?v=4","gravatar_id":"","url":"https://api.github.com/users/lmannering","html_url":"https://github.com/lmannering","followers_url":"https://api.github.com/users/lmannering/followers","following_url":"https://api.github.com/users/lmannering/following{/other_user}","gists_url":"https://api.github.com/users/lmannering/gists{/gist_id}","starred_url":"https://api.github.com/users/lmannering/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmannering/subscriptions","organizations_url":"https://api.github.com/users/lmannering/orgs","repos_url":"https://api.github.com/users/lmannering/repos","events_url":"https://api.github.com/users/lmannering/events{/privacy}","received_events_url":"https://api.github.com/users/lmannering/received_events","type":"User","site_admin":false},"created_at":"2018-05-31T08:01:20Z","updated_at":"2018-05-31T08:01:20Z","author_association":"NONE","body":"Thanks for the example @Telofy - that's really useful. I'd also like to avoid re-writing our entire codebase! "}}
{"actor":{"display_login":"lmannering"}}