Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pytest not running conftest.py at all

Tags:

pytest

I'm running pytest version 6.0.1

In the root of my project I have tests/x dirs

% ls tests/x
__init__.py     __pycache__     conftest.py     test_x.py

conftest.py contains:

print('IN CONFTEST')


def pytest_sessionstart(session):
    print('SESSIONSTART')

test_x.py contains:

def test_x():
    print("X")

It appears nothing in conftest.py runs when I run pytest:

% pytest tests/x -s
=================================================================================================== test session starts ===================================================================================================
platform darwin -- Python 3.8.5, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: OMITTED (It's the parent of "tests")
collected 1 item                                                                                                                                                                                                          

tests/x/test_x.py X
.

==================================================================================================== 1 passed in 0.01s ====================================================================================================

I'm completely stumped. I haven't found anything about anyone with an issue like this. Help!

like image 815
jbrooks Avatar asked Nov 23 '25 18:11

jbrooks


1 Answers

Since I kept stumbling here, I will leave what I found and what might be your issue too:

For me, it was a basic mistake. Reading pytest doc made it clear.

I was writing my test like this:

class Test2(unittest.TestCase):
    def test_new_valid_event(self, hello):
        print(hello)

This did not work as 'hello', my fixture was not found. Removing the unittest.TestCase fixed it.

class Test2:
    def test_new_valid_event(self, hello):
        print(hello)

Pytest does not support manual loaded fixtures. Only auto ones. So please check if this is the reason for your issue.

My setup:

  • conftest.py in same folder as in the test file.
  • I run the test with python -m pytest test_file.py
  • I also have a dunder 'init.py' file in the tests folder
like image 168
Arindam Roychowdhury Avatar answered Nov 26 '25 23:11

Arindam Roychowdhury



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!