numerous-pharmacist-91083
10/16/2025, 11:51 PMconftest.py in my root directory. That sets up some custom markers and associated commnd line options like --run_large. It was all working just fine but then I upgraded to Python 3.12 which wasn't compatible with the pytest version Pants uses by default so I setup a resolve for the test tool and specified a newer version of pytest like:
[pytest]
args = ['--log-cli-level=INFO']
install_from_resolve = "tools"
That is now using the newer version of pytest but it's no longer running my conftest.py even if I add:
[python-infer]
conftests = true
I can verify that because (1) I added print statements to things like my pytest_addoption method and (2) the command line arguments like --run_large are no longer recognized. How can I fix it?happy-kitchen-89482
10/18/2025, 12:39 AM--keep-sandboxes=always, identify the pytest sandbox and se if conftest.py has been copied into it.numerous-pharmacist-91083
10/18/2025, 2:04 AM$ pants --keep-sandboxes=always test --debug --test-force --test-output=all ./src/logutil/:: -- --run_large
ERROR: usage: pex [options] [file_or_dir] [file_or_dir] [...]
pex: error: unrecognized arguments: --run_large
inifile: None
rootdir: /tmp/pants-sandbox-2bbw6E/src/logutil
((default/3.12.10) ) oliver@astro:~/Documents/code/main/py$ ls /tmp/pants-sandbox-2bbw6E
ls: cannot access '/tmp/pants-sandbox-2bbw6E': No such file or directory
but, as you can see, it appears the andbaox was not retained. What did I do wrong?happy-kitchen-89482
10/18/2025, 2:57 AMnumerous-pharmacist-91083
10/18/2025, 6:01 PMhappy-kitchen-89482
10/18/2025, 9:33 PM-- --run_large which pex is choking on?numerous-pharmacist-91083
10/19/2025, 12:47 AM--run_large works when my conftest.py is run - it adds that as a pytest flag and then the test runs and passes.
If I remove that the test passes but I still don't get any extra logging:
$ pants --keep-sandboxes=always test --debug --test-force --test-output=all ./src/logutil/::
=========================================================================================================== test session starts ============================================================================================================
platform linux -- Python 3.12.10, pytest-8.4.2, pluggy-1.6.0
rootdir: /tmp/pants-sandbox-6Hw7P9/src/logutil
collected 1 item
src/logutil/test_json_fmt.py::test_json_fmt PASSED [100%]
============================================================================================================ 1 passed in 0.01s =============================================================================================================
$ ls /tmp/pants-sandbox-6Hw7P9
ls: cannot access '/tmp/pants-sandbox-6Hw7P9': No such file or directory
I thought maybe it was re-using sandboxes from prior runs but if I make a change to that test and re-run it still doesn't log anything. So I tried deleting all the sandboxes and re-ran and it doesn't create any new ones:
$ rm -rf /tmp/pants-sandbox-*
$ pants --keep-sandboxes=always test --debug --test-force --test-output=all ./src/logutil/::
17:45:00.76 [WARN] A plugin is calling `await Effect(InteractiveProcessResult, InteractiveProcess, process)` directly. This will cause restarting logic not to be applied. Use `await run_interactive_process(process)` or `await run_interactive_process_in_environment(process, environment_name)` instead. See <https://github.com/pantsbuild/pants/blob/release_2.28.0/src/python/pants/engine/intrinsics.py> for more details.
=========================================================================================================== test session starts ============================================================================================================
platform linux -- Python 3.12.10, pytest-8.4.2, pluggy-1.6.0
rootdir: /tmp/pants-sandbox-LI1JB5/src/logutil
collected 1 item
src/logutil/test_json_fmt.py::test_json_fmt PASSED [100%]
============================================================================================================ 1 passed in 0.01s =============================================================================================================
$ ls /tmp/pants*
ls: cannot access '/tmp/pants*': No such file or directory
However, my test does depend on conftest according to pants:
$ pants dependencies ./src/logutil/test_json_fmt.py
src/conftest.py:conftest
src/logutil/__init__.py:lib
src/logutil/json_fmt.py:lib
I'm stumped.numerous-pharmacist-91083
10/19/2025, 12:55 AMhappy-kitchen-89482
10/19/2025, 6:03 PM--test-force and to the fact that failed processes aren't cached.happy-kitchen-89482
10/19/2025, 6:03 PMhappy-kitchen-89482
10/19/2025, 6:03 PMhappy-kitchen-89482
10/19/2025, 6:04 PMawait Effect(InteractiveProcessResult, InteractiveProcess, process) directly. This will cause restarting logic not to be applied. Use await run_interactive_process(process) or await run_interactive_process_in_environment(process, environment_name) instead. See https://github.com/pantsbuild/pants/blob/release_2.28.0/src/python/pants/engine/intrinsics.py for more details.` is about.happy-kitchen-89482
10/19/2025, 6:04 PMnumerous-pharmacist-91083
10/19/2025, 6:05 PMIs there a custom plugin in the mix?I don't think so.
numerous-pharmacist-91083
10/19/2025, 6:05 PMhappy-kitchen-89482
10/19/2025, 6:06 PM--no-pantsdnumerous-pharmacist-91083
10/19/2025, 6:06 PMhappy-kitchen-89482
10/19/2025, 6:07 PM[INFO] Preserving local process execution dir /blah/blah/pants-sandbox-blah for Run Pytest for blahnumerous-pharmacist-91083
10/19/2025, 6:13 PM$ pants --keep-sandboxes=always --no-pantsd test --debug --test-force --test-output=all ./src/logutil/::
11:11:47.18 [INFO] Preserving local process execution dir /tmp/pants-sandbox-iKtiIJ for Find interpreter for constraints: CPython==3.12.10
11:11:48.39 [INFO] Completed: Scheduling: Find interpreter for constraints: CPython==3.12.10
11:11:48.40 [INFO] Completed: Scheduling: Building 1 requirement for requirements.pex from the 3rdparty/python/default.lock resolve: pytest
11:11:48.40 [INFO] Completed: Scheduling: Building pytest.pex
11:11:48.40 [INFO] Completed: Scheduling: Building local_dists.pex
11:11:48.40 [INFO] Preserving local process execution dir /tmp/pants-sandbox-CnzwJP for Test binary /usr/bin/bash.
11:11:48.40 [INFO] Preserving local process execution dir /tmp/pants-sandbox-H6NPSK for Test binary /bin/bash.
11:11:48.41 [INFO] Completed: Scheduling: Test binary /usr/bin/bash.
11:11:48.41 [INFO] Completed: Scheduling: Test binary /bin/bash.
11:11:48.42 [INFO] Completed: Scheduling: Building pytest_runner.pex
=========================================================================================================== test session starts ============================================================================================================
platform linux -- Python 3.12.10, pytest-8.4.2, pluggy-1.6.0
rootdir: /tmp/pants-sandbox-SiQm3u/src/logutil
collected 1 item
src/logutil/test_json_fmt.py::test_json_fmt PASSED
and I do see a pex in that sandbox:
$ ls -l /tmp/pants-sandbox-iKtiIJ
total 4728
-r-xr-xr-x 2 oliver oliver 4833957 Oct 19 11:08 pex
-rwxr-xr-x 1 oliver oliver 1564 Oct 19 11:11 __run.sh
I assume I should unzip -l it to see what's in there?numerous-pharmacist-91083
10/19/2025, 6:14 PMunzip -l /tmp/pants-sandbox-iKtiIJ/pex | rg test_json_fmt.py returns nothing - if I look at what's in the pex I don't see any of my code - just 3rd party dependencies and things.numerous-pharmacist-91083
10/19/2025, 6:15 PM__run.sh file.numerous-pharmacist-91083
10/19/2025, 6:15 PM$ ls /tmp/pants-sandbox-SiQm3u
ls: cannot access '/tmp/pants-sandbox-SiQm3u': No such file or directorynumerous-pharmacist-91083
10/19/2025, 6:17 PM__run.sh file and one contains a pex file but that pex doesn't contain any of my code.
• The 4th sandbox, the one that wasn't included in a log message, has been deletednumerous-pharmacist-91083
10/19/2025, 6:29 PMhappy-kitchen-89482
10/19/2025, 6:56 PMhappy-kitchen-89482
10/19/2025, 6:56 PMhappy-kitchen-89482
10/19/2025, 6:56 PMhappy-kitchen-89482
10/19/2025, 6:57 PMhappy-kitchen-89482
10/19/2025, 6:57 PMnumerous-pharmacist-91083
10/19/2025, 6:58 PM__run.sh file. One contains a __run.sh and a pex file. Nothing else. The test itself logs, rootdir: /tmp/pants-sandbox-SiQm3u/src/logutil but as you can see above, /tmp/pants-sandbox-SiQm3u doesn't exist and it isn't mentioned in the log lines before the test ran.
Also note that /tmp/pants-sandbox-SiQm3u is not mentioned in any of the log messages from before the test ran.happy-kitchen-89482
10/19/2025, 6:59 PMhappy-kitchen-89482
10/19/2025, 6:59 PMhappy-kitchen-89482
10/19/2025, 6:59 PMhappy-kitchen-89482
10/19/2025, 6:59 PMnumerous-pharmacist-91083
10/19/2025, 6:59 PMhappy-kitchen-89482
10/19/2025, 6:59 PMhappy-kitchen-89482
10/19/2025, 7:00 PMhappy-kitchen-89482
10/19/2025, 7:00 PMnumerous-pharmacist-91083
10/19/2025, 7:01 PM--debug is it's the only way I know of to get "live output" as the test runs rather than a dump of stdout/stderr after the test is complete. I'm just being impatient 🙂numerous-pharmacist-91083
10/19/2025, 7:01 PMnumerous-pharmacist-91083
10/19/2025, 7:02 PMconftest.py file is in the sandbox.
Full ouptut:
$ pants --keep-sandboxes=always --no-pantsd test --test-force --test-output=all ./src/logutil/::
12:00:25.05 [INFO] Preserving local process execution dir /tmp/pants-sandbox-kJcLqQ for Find interpreter for constraints: CPython==3.12.10
12:00:26.54 [INFO] Completed: Scheduling: Find interpreter for constraints: CPython==3.12.10
12:00:26.55 [INFO] Preserving local process execution dir /tmp/pants-sandbox-44C6Io for Building pytest.pex
12:00:26.55 [INFO] Preserving local process execution dir /tmp/pants-sandbox-9DwrBl for Building 1 requirement for requirements.pex from the 3rdparty/python/default.lock resolve: pytest
12:00:26.55 [INFO] Canceled: Building pytest.pex
12:00:26.55 [INFO] Preserving local process execution dir /tmp/pants-sandbox-7HYWSV for Building pytest.pex
12:00:27.45 [INFO] Completed: Building pytest.pex
12:00:27.45 [INFO] Completed: Scheduling: Building pytest.pex
12:00:27.51 [INFO] Completed: Building 1 requirement for requirements.pex from the 3rdparty/python/default.lock resolve: pytest
12:00:27.51 [INFO] Completed: Scheduling: Building 1 requirement for requirements.pex from the 3rdparty/python/default.lock resolve: pytest
12:00:27.51 [INFO] Preserving local process execution dir /tmp/pants-sandbox-0hWG4I for Building local_dists.pex
12:00:28.29 [INFO] Completed: Building local_dists.pex
12:00:28.30 [INFO] Completed: Scheduling: Building local_dists.pex
12:00:28.30 [INFO] Preserving local process execution dir /tmp/pants-sandbox-dgvdMK for Test binary /bin/bash.
12:00:28.30 [INFO] Preserving local process execution dir /tmp/pants-sandbox-6DCiDC for Test binary /usr/bin/bash.
12:00:28.32 [INFO] Completed: Scheduling: Test binary /bin/bash.
12:00:28.32 [INFO] Completed: Scheduling: Test binary /usr/bin/bash.
12:00:28.32 [INFO] Preserving local process execution dir /tmp/pants-sandbox-A2d9LR for Building pytest_runner.pex
12:00:29.16 [INFO] Completed: Building pytest_runner.pex
12:00:29.16 [INFO] Completed: Scheduling: Building pytest_runner.pex
12:00:29.17 [INFO] Preserving local process execution dir /tmp/pants-sandbox-lNudhT for Run Pytest for src/logutil/test_json_fmt.py:tests
12:00:29.33 [INFO] Completed: Scheduling: Run Pytest for src/logutil/test_json_fmt.py:tests
12:00:29.34 [INFO] Completed: Run Pytest - src/logutil/test_json_fmt.py:tests - succeeded.
============================= test session starts ==============================
platform linux -- Python 3.12.10, pytest-8.4.2, pluggy-1.6.0
rootdir: src/logutil
collected 1 item
src/logutil/test_json_fmt.py::test_json_fmt PASSED [100%]
- generated xml file: src.logutil.test_json_fmt.py.tests.xml -
$ $ ls /tmp/pants-sandbox-lNudhT/src
conftest.py logutilnumerous-pharmacist-91083
10/19/2025, 7:03 PMconftest.py doesn't appear to be run.numerous-pharmacist-91083
10/19/2025, 7:04 PMconftest.py and it's as expected - it's my code that adds the --run_large flag which used to work before I upgraded pytest)happy-kitchen-89482
10/19/2025, 7:23 PMnumerous-pharmacist-91083
10/20/2025, 12:36 AMconftest.py is being ignored. Any thoughts there?happy-kitchen-89482
10/20/2025, 1:23 AM__run.sh or the scripts it points to) to figure it out. But the good news is that conftest.py is in the sandbox, so now you get to debug this at the pytest levelnumerous-pharmacist-91083
10/20/2025, 1:54 AMnumerous-pharmacist-91083
10/20/2025, 5:58 PMpytest.ini, pyproject.toml, etc.) in the sandbox root pytest no longer walks up the directory tree to find conftest.py files. There's 2 possible workarounds:
1. put a file like pytest.ini in the root
2. pass the --confcutdir flag
I have verified that both work. Letting you know as I assume other Pants users are going to hit this issue so I'm thinking Pants might want want to add one of these fixes as part of the standard test task. Thoughts?numerous-pharmacist-91083
10/20/2025, 6:04 PMfiles(
name = 'pytest_marker',
sources = ['pytest.ini']
)
python_test_utils(
name='conftest',
sources=['conftest.py'],
dependencies=[':pytest_marker'],
)happy-kitchen-89482
10/20/2025, 10:21 PMnumerous-pharmacist-91083
10/20/2025, 10:35 PMhappy-kitchen-89482
10/21/2025, 12:58 AMhappy-kitchen-89482
10/21/2025, 12:58 AMnumerous-pharmacist-91083
10/21/2025, 1:00 AM--confcutdir solution doesn't feel too magic to me. You just pass that as an argument to pytest setting it to src in the sandbox. There's already magic to automatically add the conftest.py to the set of dependencies for all tests, so it feels in keeping with the current level of magic.
But I can also look into sending you a PR with documentation if that still feels too magic.happy-kitchen-89482
10/21/2025, 1:46 AM--confcutdirhappy-kitchen-89482
10/21/2025, 1:46 AMnumerous-pharmacist-91083
10/21/2025, 4:09 PMSets a directory where search upwards forSo I think setting that tofiles stops. By default, pytest will stop searching forconftest.pyfiles upwards from `pytest.ini`/`tox.ini`/`setup.cfg` of the project if any, or up to the file-system root.conftest.py
src in the sandbox restores the previous behavior.happy-kitchen-89482
10/21/2025, 4:22 PMpytest.ini or similar then shouldn't it keep going to the filesystem root?happy-kitchen-89482
10/21/2025, 4:22 PMhappy-kitchen-89482
10/21/2025, 4:22 PMnumerous-pharmacist-91083
10/21/2025, 4:24 PMIf there is noNot anymore. That was the change in 8.5 (or 7.4 depending on who you believe). I think it's a security thing. If there's noor similar then shouldn't it keep going to the filesystem root?pytest.ini
pytest.ini they can't figure out where they've left your project and entered the uncharted domain of the filesystem as a whole so they they don't want to run code that's outside your project. So, if they can't find a project marker file they stop traversing up.numerous-pharmacist-91083
10/21/2025, 4:25 PMThis is due to this change from the changelog:
#11043: When --confcutdir is not specified, and there is no config file present, the conftest cutoff directory (--confcutdir) is now set to the rootdir. Previously in such cases, conftest.py files would be probed all the way to the root directory of the filesystem. If you are badly affected by this change, consider adding an empty config file to your desired cutoff directory, or explicitly set --confcutdir.
numerous-pharmacist-91083
10/21/2025, 4:31 PM/. Here's part of the (long) writeup about what the rootdir is:
pytest determines afor each test run which depends on the command line arguments (specified test files, paths) and on the existence of configuration files. The determinedrootdirandrootdirare printed as part of the pytest header during startup.configfile
Here’s a summary whatusespytestfor:rootdir
• Construct nodeids during collection; each test is assigned a unique nodeid which is rooted at theand takes into account the full path, class name, function name and parametrization (if any).rootdir
• Is used by plugins as a stable location to store project/test run specific information; for example, the internal cache plugin creates asubdirectory in.pytest_cacheto store its cross-test run state.rootdir
•
happy-kitchen-89482
10/21/2025, 7:10 PMhappy-kitchen-89482
10/21/2025, 7:10 PM--confcutdir to the root of the sandbox, and actually doing so unconditionally is never wrong.happy-kitchen-89482
10/21/2025, 7:10 PMnumerous-pharmacist-91083
10/21/2025, 7:10 PMnumerous-pharmacist-91083
10/21/2025, 7:11 PMhappy-kitchen-89482
10/21/2025, 7:11 PMhappy-kitchen-89482
10/21/2025, 7:12 PMpytest_args in src/python/pants/backend/python/goals/pytest_runner.pyhappy-kitchen-89482
10/21/2025, 7:13 PM--confcutdir=./src should do itnumerous-pharmacist-91083
10/21/2025, 7:18 PM