<#22480 Pants will confusingly strip the name of t...
# github-notifications
c
#22480 Pants will confusingly strip the name of the sandbox from all pytest terminal output Issue created by jmoldow Describe the bug When running pytest, pants will strip the name of the sandbox from all terminal output, leaving invalid and confusing messages in the terminal. Pants version 2.27.0 OS MacOS. Haven't tried on Linux. Additional info Test that reproduces the bug: # projects/test_foo.py import os def test_foo(): print(os.getcwd()) extra = f"{os.getcwd()}/extra" print(extra) assert os.getcwd() in extra assert False, "this was actually successful" # projects/BUILD python_unit_tests(name="tests")
pants --keep-sandboxes=always test projects/test_foo.py:tests -- -l
Copy code
16:25:31.92 [INFO] Preserving local process execution dir /Users/jordan/git/pants.d/tmp/pants-sandbox-4DThMk for Run Pytest for projects/test_foo.py:tests
16:25:35.94 [INFO] Completed: Scheduling: Run Pytest for projects/test_foo.py:tests
16:25:35.94 [ERROR] Completed: Run Pytest - projects/test_foo.py:tests - failed (exit code 1).
============================= test session starts ==============================
platform darwin -- Python 3.11.11, pytest-7.4.4, pluggy-1.6.0
rootdir: /Users/jordan/git/pants.d/tmp/pants-sandbox-4DThMk
configfile: pytest.ini
plugins: asyncio-0.23.8, docker-3.2.3, xdist-3.7.0, cov-6.2.1, mock-3.14.1, opentelemetry-1.1.0, hypothesis-6.127.9
asyncio: mode=Mode.AUTO
collected 1 item

projects/test_foo.py F                                                   [100%]

=================================== FAILURES ===================================
___________________________________ test_foo ___________________________________

    def test_foo():
        print(os.getcwd())
        extra = f"{os.getcwd()}/extra"
        print(extra)
        assert os.getcwd() in extra
>       assert False, "this was actually successful"
E       AssertionError: this was actually successful
E       assert False

extra      = '/Users/jordan/git/pants.dextra'

projects/test_foo.py:8: AssertionError
----------------------------- Captured stdout call -----------------------------
/Users/jordan/git/pants.d/tmp/pants-sandbox-4DThMk
/Users/jordan/git/pants.dextra
- generated xml file: /Users/jordan/git/pants.dprojects.test_foo.py.tests.xml -
=========================== short test summary info ============================
FAILED projects/test_foo.py::test_foo - AssertionError: this was actually successful
============================== 1 failed in 0.13s ===============================


✕ projects/test_foo.py:tests failed in 3.92s.
Note that: •
/tmp/pants-sandbox-4DThMk
is successfully printed in the terminal output: the first line in the capture output is
/Users/jordan/git/pants.d/tmp/pants-sandbox-4DThMk
•
/tmp/pants-sandbox-4DThMk/
is stripped from everywhere it should appear: the second line in the capture output is
/Users/jordan/git/pants.dextra
, which is not a real path. When re-running the
__run.sh
script in the sandbox, all the terminal output is correct:
/Users/jordan/git/pants.d/tmp/pants-sandbox-4DThMk/__run.sh
Copy code
================================================= test session starts ==================================================
platform darwin -- Python 3.11.11, pytest-7.4.4, pluggy-1.6.0
rootdir: /Users/jordan/git/pants.d/tmp/pants-sandbox-4DThMk
configfile: pytest.ini
plugins: asyncio-0.23.8, docker-3.2.3, xdist-3.7.0, cov-6.2.1, mock-3.14.1, opentelemetry-1.1.0, hypothesis-6.127.9
asyncio: mode=Mode.AUTO
collected 1 item

projects/test_foo.py F                                                                                           [100%]

======================================================= FAILURES =======================================================
_______________________________________________________ test_foo _______________________________________________________

    def test_foo():
        print(os.getcwd())
        extra = f"{os.getcwd()}/extra"
        print(extra)
        assert os.getcwd() in extra
>       assert False, "this was actually successful"
E       AssertionError: this was actually successful
E       assert False

extra      = '/Users/jordan/git/pants.d/tmp/pants-sandbox-4DThMk/extra'

projects/test_foo.py:8: AssertionError
------------------------------------------------- Captured stdout call -------------------------------------------------
/Users/jordan/git/pants.d/tmp/pants-sandbox-4DThMk
/Users/jordan/git/pants.d/tmp/pants-sandbox-4DThMk/extra
--- generated xml file: /Users/jordan/git/pants.d/tmp/pants-sandbox-4DThMk/projects.test_foo.py.tests.xml ----
=============================================== short test summary info ================================================
FAILED projects/test_foo.py::test_foo - AssertionError: this was actually successful
================================================== 1 failed in 0.05s ===================================================
pantsbuild/pants