question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question]is it intentional that all conftests get loaded under this scenario?

See original GitHub issue

Here 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:closed
  • Created 4 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
symonkcommented, Aug 3, 2019

ok I will reproduce a small example tomorrow and we can have a look 😃 thanks for your time and have a good night

0reactions
symonkcommented, Aug 9, 2019

sorry been a busy week, will get back onto this now!

Read more comments on GitHub >

github_iconTop Results From Across the Web

All my test functions are loading a fixture that is in the conftest ...
I have tried to place just the fixture inside the "Test_file.py" and the problem is solved, but i read that it's a good...
Read more >
How To Do Parameterization In Pytest With Selenium?
Parameterized tests help best in such scenarios. In this Selenium Python tutorial, we will deep dive into parameterization in pytest – a ...
Read more >
pytest Documentation
pytest will run all files of the form test_*.py or *_test.py in the current directory ... 18.1 Requiring/Loading plugins in a test module...
Read more >
An Elegant Guide to Testing Your Data Science Pipeline ...
Getting Started with Pytest. As a quick introduction, Pytest is a testing framework for writing test codes, executing them on a coded pipeline...
Read more >
Feedback on my pytest / Selenium project - Questions - The Club
Anyhow. If anyone spots a particularly rankling code smell let me know. All feedback is greatly appreciated. Code below: conftest.py import pytest from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found