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

7 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

4 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.

3 Likes

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.

“somewhere important to pytest” is called conftest.py, and they appear to be unwilling to even consider a PR which would allow an alternative location.

You’ve misread the previous reply

Somewhere “importable by pytest”, not somewhere “important to pytest”

conftest.py is more-or-less treated as a plugin that is always loaded

If you need to name it something else, you can rename it and then always specify the name as a plugin

1 Like

it’s certainly more than just simply renaming the top-level conftest.py, say to foobar.py and passing foobar as the name of the pytest plugin to load at startup.

While your proposal works for calling pytest as python -m pytest, it doesn’t work for calling pytest directly. In the latter case plugins have to be blessed in, well, conftest.py, as far as I can see in the docs. These two different ways of calling pytest return slightly different results in our case.

So just do that then? Presumably you control exactly how your tests are run in CI and how you document your expected development process in your contributor guide.

Any project that prioritizes user experience would take care to construct a manifest of the files they create (or expect) and then delete only those. Frankly, issuing blanket rm -f commands with random file globs is irresponsible of autotools regardless of how long they have been doing it.

3 Likes