[Question]is it intentional that all conftests get loaded under this scenario?
See original GitHub issueHere is an example tree (excuse the cache dirs):
C:.
├───.idea
│ misc.xml
│ modules.xml
│ pycharmer.iml
│ workspace.xml
│
└───tests
│ conftest.py
│
├───interface
│ ├───interface
│ │ │ conftest.py
│ │ │ test_intf.py
│ │ │
│ │ └───__pycache__
│ │ conftest.cpython-37-pytest-5.0.1.pyc
│ │ test_intf.cpython-37-pytest-5.0.1.pyc
│ │
│ └───system
│ │ conftest.py
│ │ test_sys.py
│ │
│ └───__pycache__
│ conftest.cpython-37-pytest-5.0.1.pyc
│ test_sys.cpython-37-pytest-5.0.1.pyc
│
├───production
│ │ conftest.py
│ │ test_prod.py
│ │
│ ├───.pytest_cache
│ │ │ .gitignore
│ │ │ CACHEDIR.TAG
│ │ │ README.md
│ │ │
│ │ └───v
│ │ └───cache
│ │ nodeids
│ │ stepwise
│ │
│ └───__pycache__
│ conftest.cpython-37-pytest-5.0.1.pyc
│ test_prod.cpython-37-pytest-5.0.1.pyc
│
└───__pycache__
conftest.cpython-37-pytest-5.0.1.pyc
Production file:
import pytest
class TestProduction:
@pytest.mark.prod
def test_production(self):
assert 1 == 1
System file:
import pytest
class TestSystem:
@pytest.mark.system
def test_system(self):
assert 1 == 1
Integration file:
import pytest
class TestIntegration:
@pytest.mark.integration
def test_integration(self):
assert 1 == 1
is it intentional that when executing the following:
pytest -m prod
that all 3 conftest files get loaded here? I thought the ones not in root/prod (e.g interface/system would NOT be loaded in that scenario, guess i am misunderstanding?)
rootdir: C:\Users\sy\PycharmProjects\pycharmer
collecting ... prod conftest
PLUGIN registered: <module 'conftest' from 'C:\\Users\\sy\\PycharmProjects\\pycharmer\\tests\\production\\conftest.py'>
interface conf
PLUGIN registered: <module 'conftest' from 'C:\\Users\\sy\\PycharmProjects\\pycharmer\\tests\\interface\\interface\\conftest.py'>
sys conf
PLUGIN registered: <module 'conftest' from 'C:\\Users\\sy\\PycharmProjects\\pycharmer\\tests\\interface\\system\\conftest.py'>
collected 3 items / 2 deselected / 1 selected
How do autouse fixtures work in this regard? since all 3 are collected with an autouse function scoped fixture apply to EVERY test? lets say i had the following in production folders conftest.py:
@pytest.fixture(scope='function', autouse=True)
def do_fixture(request):
print('AUTO USE ON')
Will this execute on EVERY test then? how do you have only autouse fixtures apply to tests in their own directory respectively, e.g the above fixture would only apply to the tests in the ‘production directory’? Just trying to gain an understanding on how this stuff works
I’m reading about fixtures, it states that ‘plugins’ should be careful with autouse fixtures, what makes a conftest.py file considered a ‘plugin’ ?
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (11 by maintainers)
ok I will reproduce a small example tomorrow and we can have a look 😃 thanks for your time and have a good night
sorry been a busy week, will get back onto this now!