{"action":"created","issue":{"url":"https://api.github.com/repos/pytest-dev/pytest/issues/4014","repository_url":"https://api.github.com/repos/pytest-dev/pytest","labels_url":"https://api.github.com/repos/pytest-dev/pytest/issues/4014/labels{/name}","comments_url":"https://api.github.com/repos/pytest-dev/pytest/issues/4014/comments","events_url":"https://api.github.com/repos/pytest-dev/pytest/issues/4014/events","html_url":"https://github.com/pytest-dev/pytest/issues/4014","id":362739573,"node_id":"MDU6SXNzdWUzNjI3Mzk1NzM=","number":4014,"title":"PytestWarning backports already imported","user":{"login":"jaraco","id":308610,"node_id":"MDQ6VXNlcjMwODYxMA==","avatar_url":"https://avatars2.githubusercontent.com/u/308610?v=4","gravatar_id":"","url":"https://api.github.com/users/jaraco","html_url":"https://github.com/jaraco","followers_url":"https://api.github.com/users/jaraco/followers","following_url":"https://api.github.com/users/jaraco/following{/other_user}","gists_url":"https://api.github.com/users/jaraco/gists{/gist_id}","starred_url":"https://api.github.com/users/jaraco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaraco/subscriptions","organizations_url":"https://api.github.com/users/jaraco/orgs","repos_url":"https://api.github.com/users/jaraco/repos","events_url":"https://api.github.com/users/jaraco/events{/privacy}","received_events_url":"https://api.github.com/users/jaraco/received_events","type":"User","site_admin":false},"labels":[{"id":615327396,"node_id":"MDU6TGFiZWw2MTUzMjczOTY=","url":"https://api.github.com/repos/pytest-dev/pytest/labels/plugin:%20warnings","name":"plugin: warnings","color":"fef2c0","default":false},{"id":224849198,"node_id":"MDU6TGFiZWwyMjQ4NDkxOTg=","url":"https://api.github.com/repos/pytest-dev/pytest/labels/type:%20question","name":"type: question","color":"cc317c","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-09-21T19:06:03Z","updated_at":"2018-09-22T21:54:22Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"On projects that have `backports` modules in use, I see this warning after running the tests:\r\n\r\n```\r\n/Users/jaraco/code/yg/G/panoptic/.tox/python/lib/python2.7/site-packages/_pytest/assertion/rewrite.py:274: PytestWarning: Module already imported so cannot be rewritten: backports\r\n  self.config,\r\n```\r\n\r\n`backports` is a namespace package, so maybe the warning should be suppressed for it.\r\n\r\nHere's how to reproduce the issue:\r\n\r\n```\r\n $ cat > test_this.py\r\ndef test():\r\n        pass\r\n$ python2.7 -m rwt -q pytest backports.unittest_mock pytest-flake8 -- -m pytest\r\n============================================================================================ test session starts ============================================================================================\r\nplatform darwin -- Python 2.7.15, pytest-3.8.0, py-1.6.0, pluggy-0.7.1\r\nrootdir: /Users/jaraco/draft/backports, inifile:\r\nplugins: flake8-1.0.2, backports.unittest-mock-1.4\r\ncollected 1 item\r\n\r\ntest_this.py .                                                                                                                                                                                        [100%]\r\n\r\n============================================================================================= warnings summary ==============================================================================================\r\n/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/rwt-7YqacE/_pytest/assertion/rewrite.py:274: PytestWarning: Module already imported so cannot be rewritten: backports\r\n  self.config,\r\n\r\n-- Docs: https://docs.pytest.org/en/latest/warnings.html\r\n=================================================================================== 1 passed, 1 warnings in 0.01 seconds ====================================================================================\r\n```\r\n\r\nThe issue only seems to happen on Python 2.7.\r\n\r\nInterestingly, it also only seems to happen if pytest-flake8 is included even though I don't see any references to backports in pytest-flake8 or its dependencies.\r\n\r\nIs there something that backports.unittest_mock should do to help suppress this warning?"},"comment":{"url":"https://api.github.com/repos/pytest-dev/pytest/issues/comments/423776103","html_url":"https://github.com/pytest-dev/pytest/issues/4014#issuecomment-423776103","issue_url":"https://api.github.com/repos/pytest-dev/pytest/issues/4014","id":423776103,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMzc3NjEwMw==","user":{"login":"jaraco","id":308610,"node_id":"MDQ6VXNlcjMwODYxMA==","avatar_url":"https://avatars2.githubusercontent.com/u/308610?v=4","gravatar_id":"","url":"https://api.github.com/users/jaraco","html_url":"https://github.com/jaraco","followers_url":"https://api.github.com/users/jaraco/followers","following_url":"https://api.github.com/users/jaraco/following{/other_user}","gists_url":"https://api.github.com/users/jaraco/gists{/gist_id}","starred_url":"https://api.github.com/users/jaraco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaraco/subscriptions","organizations_url":"https://api.github.com/users/jaraco/orgs","repos_url":"https://api.github.com/users/jaraco/repos","events_url":"https://api.github.com/users/jaraco/events{/privacy}","received_events_url":"https://api.github.com/users/jaraco/received_events","type":"User","site_admin":false},"created_at":"2018-09-22T21:54:22Z","updated_at":"2018-09-22T21:54:22Z","author_association":"CONTRIBUTOR","body":"In the case of `backports.*`, that namespace uses native namespaces ([not declaring them to setuptools/pkg_resources](https://github.com/jaraco/backports.unittest_mock/blob/a4f9fbe456ae8e1072ab4863ca8cc4340b46a50e/setup.py#L9)), so I would expect it not to be influenced (much) by pkg_resources.\r\n\r\n```\r\n~ $ python2.7 -m rwt -q backports.unittest_mock\r\nPython 2.7.15 (default, Jun 20 2018, 13:24:23)\r\n[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n\r\n>>> import pkg_resources, sys\r\n>>> 'backports' in sys.modules\r\nFalse\r\n```"}}
{"actor":{"display_login":"jaraco"}}