3

I'm using Python3.8 with PyTest. By default, pytest uses

./conftest.py

to build and import fixtures. Is it possible to launch pytest and use a different file to load the fixtures -- i.e. specify a different file other than conftest.py?

Dave
  • 15,639
  • 133
  • 442
  • 830
  • 1
    This particular name is hardcoded, so no. You can pass a custom module as a plugin though, e.g. rename `conftest.py` to `spam.py` and run `PYTHONPATH=. pytest -p spam`. – hoefling Aug 03 '20 at 21:16
  • If you were to pass the "-p spam" option, would that override whatever is in the "conftest.py" file? – Dave Aug 04 '20 at 00:30
  • No, the `conftest.py` will not be overridden. – hoefling Aug 04 '20 at 11:49
  • I'm interested in some way to deactivate/activate certain fixtures for different test runs. If there's a way to control what fixtures are activated through the command line, that would work as well. – Dave Aug 05 '20 at 18:36
  • You could implement that logic in fixtures themselves, like `if request.config.getoption('--myflag'): do stuff`. The fixtures will still be loaded and executed, but will do nothing if `--myflag` not provided. – hoefling Aug 05 '20 at 19:34
  • 1
    Renaming that file would be really great as that name is so stupid and confusing :-\ – t3chb0t Mar 06 '22 at 19:03

0 Answers0