Pytest's conftest.py naming (in)compatibility with autoconf

We found in a hard way that pytest is not playing along nicely with autoconf (or any tool which might use conftest* “file namespace” for their own purposes, as autoconf clobbers the conftest* files in the project’s root/build directory.

If you cannot do a split build in your autoconf-using project you cannot put pytest’s conftest.py there, so basically you need to restore conftest.py after ./configure run in some way.
See Is it possible to use some other name for conftest.py file? · pytest-dev/pytest · Discussion #13157 · GitHub
and
Re: autoconf (configure) clobbers conftest.py - fix?

It’s true that autoconf is not universally loved, but OTOH even cpython is using it!
IMHO pytest ought to fix this, as otherwise it’s kind of “move fast and break things” attitude FOSS doesn’t appreciate, besides being pain in the neck to work around. I am interested to hear the list’s opinions on this.

Its Unfair to call a 20 years old mechanism move fast and break thing’s

Conftest was a thing before pytest was called pytest

5 Likes

Unfair? 20 years of breaking de facto standards don’t look good. Besides, autoconf was creating and compiling conftest.c files (and then doing rm -f conftest*) back in 1990 or so.

Last but not the least, the way you talk on Is it possible to use some other name for conftest.py file? · pytest-dev/pytest · Discussion #13157 · GitHub is breaking pytest’s Code of Conduct: pytest/CODE_OF_CONDUCT.md at main · pytest-dev/pytest · GitHub
(your tone is rather unwelcoming, to say the least)

From the autoconf maintainer’s response:

I can suggest two workarounds:

  1. Put conftest.py in a subdirectory :wink: Doesn’t pytest recommend
    you put it in a tests subdirectory along with the actual tests?

  2. Always use split builds - that is, run configure from a different
    directory than your source tree…

You mention option 2 in your post, but not option 1

Does putting the test code in a tests subdirectory not work? I don’t think I’ve ever seen a conftest.py file at the project root

3 Likes

well, you can see it here:

and no, we don’t even have a top-level tests/

Im done without this topic and the communication style

I will disengage

Goodbye

conftest.py files are well established in pytest since its inception, it is something really hard to change without breaking thousands of test suites downstream.

I suggest just moving the tests and the conftest.py files to a tests subdirectory, this seems to be a reasonable workaround.

1 Like

nobody asked for conftest.py to be renamed. What was asked, and promptly dismissed (“not sensible for pytest to accommodate autoconf” (!)), was a possibility to have an alternative name for conftest.py, outside of the namespace clobbered by ./configure and libtool scripts.

What’s “not sensible” about it?

Sorry you did not answer my question: can’t you just move the conftest.py file to tests or src directory?

We don’t even have tests/ - our doctests (and a number of specific tests run by pytest) are scattered across the repo. We tried to move conftest.py to src/, but it didn’t work for some reason.

Hmm. Well a conftest.py file is just a normal plugin, which pytest loads automatically.

Perhaps you can rename conftest.py to something else (say myfixtures.py), put it somewhere that is importable by pytest, then execute pytest -p myfixtures.