{"action":"created","issue":{"url":"https://api.github.com/repos/pytest-dev/pytest/issues/3161","repository_url":"https://api.github.com/repos/pytest-dev/pytest","labels_url":"https://api.github.com/repos/pytest-dev/pytest/issues/3161/labels{/name}","comments_url":"https://api.github.com/repos/pytest-dev/pytest/issues/3161/comments","events_url":"https://api.github.com/repos/pytest-dev/pytest/issues/3161/events","html_url":"https://github.com/pytest-dev/pytest/issues/3161","id":292532635,"number":3161,"title":"Scope of session fixtures broken when created dynamically","user":{"login":"ceridwen","id":8268008,"avatar_url":"https://avatars1.githubusercontent.com/u/8268008?v=4","gravatar_id":"","url":"https://api.github.com/users/ceridwen","html_url":"https://github.com/ceridwen","followers_url":"https://api.github.com/users/ceridwen/followers","following_url":"https://api.github.com/users/ceridwen/following{/other_user}","gists_url":"https://api.github.com/users/ceridwen/gists{/gist_id}","starred_url":"https://api.github.com/users/ceridwen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ceridwen/subscriptions","organizations_url":"https://api.github.com/users/ceridwen/orgs","repos_url":"https://api.github.com/users/ceridwen/repos","events_url":"https://api.github.com/users/ceridwen/events{/privacy}","received_events_url":"https://api.github.com/users/ceridwen/received_events","type":"User","site_admin":false},"labels":[{"id":604021555,"url":"https://api.github.com/repos/pytest-dev/pytest/labels/topic:%20fixtures","name":"topic: fixtures","color":"5319e7","default":false},{"id":224849198,"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-01-29T19:34:35Z","updated_at":"2018-02-01T21:14:21Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"This is a continuation of the discussion in #519 and #2959, and it may be related to one or both of those issues.  I have a test suite where I have to run some very expensive configuration before running the entire test suite, and the set of possible configurations is the Cartesian product of modes that are fixed with flavors that I need to be able to pass in at run-time.  Using the example @RonnyPfannschmidt provided in #519 with @popravich's edit and fixing indentation, I ended up with this code:\r\n\r\n```python\r\ndef pytest_configure(config):\r\n    class DynamicFixturePlugin(object):\r\n        @pytest.fixture(scope='session', params=config.getoption('--reprovision-flavors').split(','))\r\n        def flavor(self, request):\r\n            return request.param\r\n    config.pluginmanager.register(DynamicFixturePlugin(), 'flavor-fixture')\r\n\r\n@pytest.fixture(scope='session', params=['vxlan', pytest.mark.skipif(\"not pytest.config.getoption('--reprovision-fabric')\")('vlan')])\r\ndef encap(request):\r\n    return request.param\r\n\r\n@pytest.fixture(scope='session', autouse='True')\r\ndef reprovision(request, flavor, encap):\r\n    fabric_name = request.config.getoption('--reprovision-fabric')\r\n    if fabric_name:\r\n        kubernetes_.deploy(fabric_name, reinstall=request.config.getoption('--reprovision-reinstall'), encap=encap, **kubernetes_.FLAVORS[flavor])\r\n```\r\n\r\nThis half-works.  What happens is that for the first two flavor-encap combinations, foo and bar and vxlan, `reprovision` runs once for each full execution of the test suite.  For the second two flavor-encap combinations, reprovision runs twice for every test, as if it was function-scoped rather than session-scoped.  I tried this alternate form of the above code with the same result:\r\n\r\n```python\r\ndef pytest_configure(config):\r\n    class DynamicFixturePlugin(object):\r\n        @pytest.fixture(scope='session', params=config.getoption('--reprovision-flavors').split(','))\r\n        def flavor(self, request):\r\n            return request.param\r\n    config.pluginmanager.register(DynamicFixturePlugin(), 'flavor-fixture')\r\n    class DynamicFixturePlugin2(object):\r\n        @pytest.fixture(scope='session', params=['vxlan', 'vlan'] if config.getoption('--reprovision-fabric') else [])\r\n        def encap(self, request):\r\n            return request.param\r\n    config.pluginmanager.register(DynamicFixturePlugin2(), 'encap-fixture')\r\n\r\n@pytest.fixture(scope='session', autouse='True')\r\ndef reprovision(request, flavor, encap):\r\n    fabric_name = request.config.getoption('--reprovision-fabric')\r\n    if fabric_name:\r\n        kubernetes_.deploy(fabric_name, reinstall=request.config.getoption('--reprovision-reinstall'), encap=encap, **kubernetes_.FLAVORS[flavor])\r\n```\r\n\r\nThis is similar to how `pytest_generate_tests` breaks session-scoped fixtures.\r\n\r\nI'm assuming these are bugs.  How hard do you think it will be to fix them?  Can anyone point me to where I need to look to start, assuming it's possible?\r\n\r\nThis is with pytest 3.2.0 on Python3 and Mac OS X 10.12.6.  I have pytest-notifier, pytest-html, and pytest-metadata installed."},"comment":{"url":"https://api.github.com/repos/pytest-dev/pytest/issues/comments/362403708","html_url":"https://github.com/pytest-dev/pytest/issues/3161#issuecomment-362403708","issue_url":"https://api.github.com/repos/pytest-dev/pytest/issues/3161","id":362403708,"user":{"login":"cheezman34","id":3431603,"avatar_url":"https://avatars1.githubusercontent.com/u/3431603?v=4","gravatar_id":"","url":"https://api.github.com/users/cheezman34","html_url":"https://github.com/cheezman34","followers_url":"https://api.github.com/users/cheezman34/followers","following_url":"https://api.github.com/users/cheezman34/following{/other_user}","gists_url":"https://api.github.com/users/cheezman34/gists{/gist_id}","starred_url":"https://api.github.com/users/cheezman34/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cheezman34/subscriptions","organizations_url":"https://api.github.com/users/cheezman34/orgs","repos_url":"https://api.github.com/users/cheezman34/repos","events_url":"https://api.github.com/users/cheezman34/events{/privacy}","received_events_url":"https://api.github.com/users/cheezman34/received_events","type":"User","site_admin":false},"created_at":"2018-02-01T21:14:21Z","updated_at":"2018-02-01T21:14:21Z","author_association":"NONE","body":"https://github.com/pytest-dev/pytest/pull/3183"}}
{"actor":{"display_login":"cheezman34"}}