pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Option to load initial conftest.py from rootdir rather than current working directory

Open henzef opened this issue 4 years ago • 3 comments

Would it be possible to add an option to load the initial conftest.py from the rootdir (which can be specified on the commandline) instead of using the automatic discovery that is explained in https://docs.pytest.org/en/6.2.x/writing_plugins.html#plugin-discovery-order-at-tool-startup ?

This seems to be the missing piece of the puzzle that would allow me to execute my test suite independently from the current working directory. Consider e.g. the following commandline:

pytest -c /home/user/project/pytest.ini --rootdir=/home/user/project --an-argument-of-my-plugin=./some/relative/path

which only works if the current working directory is below /home/user/project. For now I used a wrapper script that changed the cwd before starting pytest, but this fell apart when I introduced commandline arguments that take a (possibly relative) path.

henzef avatar Nov 15 '21 21:11 henzef

Is this solve in 8.1.0 with https://github.com/pytest-dev/pytest/pull/11962 ?

kdeldycke avatar Mar 04 '24 14:03 kdeldycke

If understand the pyproject.toml discovery correctly, it starts searching from the current working directory, right? If yes, then it will not help in this case.

henzef avatar Mar 04 '24 14:03 henzef

I don't know if this is a combination of recent Pytest or Poetry upgrade, but moving my tests from my_package/tests/* to the root of my repository at tests/* seems to have fixed the issue for me.

And this over 3 different projects:

  • https://github.com/kdeldycke/click-extra/commit/42fe671daa3bc5bba9e3c5612a9ebae003ee4574
  • https://github.com/kdeldycke/meta-package-manager/commit/3ca602af863592265bf4b756d95ea18f0c556cd5
  • https://github.com/kdeldycke/mail-deduplicate/commit/f144320631a1fd45c99a729ba036c95a361fcce1

Pretty sure forcing a code layout is not a definitive solution though, but wanted to keep this issue up to date with my current observations.

kdeldycke avatar May 28 '24 08:05 kdeldycke