As stated in a comment to the referenced question, you have to substitute pytest by the actual path to the pytest executable:

python -m trace -c -m -C . <pytest_executable_absolute_path> test_script.py

Under *nix, you should be able to localize the pytest executable using which pytest, under Windows using where pytest (thanks to @hoefling for reminding me of that).

Answer from MrBean Bremen on Stack Overflow
🌐
pytest
docs.pytest.org › en › 6.2.x › usage.html
Usage and Invocations — pytest documentation
By using this option you make sure a trace is shown. The -r flag can be used to display a “short test summary info” at the end of the test session, making it easy in large test suites to get a clear picture of all failures, skips, xfails, etc. It defaults to fE to list failures and errors. ... # content of test_example.py import pytest @pytest.fixture def error_fixture(): assert 0 def test_ok(): print("ok") def test_fail(): assert 0 def test_error(error_fixture): pass def test_skip(): pytest.skip("skipping this test") def test_xfail(): pytest.xfail("xfailing this test") @pytest.mark.xfail(reason="always xfail") def test_xpass(): pass
🌐
pytest
docs.pytest.org › en › stable › how-to › output.html
Managing pytest’s output - pytest documentation
pytest --showlocals # show local variables in tracebacks pytest -l # show local variables (shortcut) pytest --no-showlocals # hide local variables (if addopts enables them) pytest --capture=fd # default, capture at the file descriptor level pytest --capture=sys # capture at the sys level pytest --capture=no # don't capture pytest -s # don't capture (shortcut) pytest --capture=tee-sys # capture to logs but also output to sys level streams pytest --tb=auto # (default) 'long' tracebacks for the first and last # entry, but 'short' style for the other entries pytest --tb=long # exhaustive, informative traceback formatting pytest --tb=short # shorter traceback format pytest --tb=line # only one line per failure pytest --tb=native # Python standard library formatting pytest --tb=no # no traceback at all
🌐
pytest
docs.pytest.org › en › stable › how-to › failures.html
How to handle test failures - pytest documentation
When tests are complete, the system will default back to the system Pdb trace UI. With --pdb passed to pytest, the custom internal Pdb trace UI is used with both breakpoint() and failed tests/unhandled exceptions.
🌐
PyPI
pypi.org › project › pytest-trace
pytest-trace · PyPI
June 19, 2022 - Save OpenTelemetry spans generated during testing
      » pip install pytest-trace
    
Published   Jun 19, 2022
Version   1.0.0
🌐
O'Reilly
oreilly.com › library › view › python-testing-with › 9781680509427 › f_0150.xhtml
Debugging with pdb - Python Testing with pytest [Book]
February 18, 2022 - Use the --pdb flag. With --pdb, pytest will stop at the point of failure. In our case, that will be at the assert len(the_list) == 2 line. Use the --trace flag.
Author   Brian Okken
Published   2022
Pages   274
🌐
Qxf2 BLOG
qxf2.com › home › debugging in python using pytest.set_trace()
Debugging in Python using pytest.set_trace() - Qxf2 BLOG
October 30, 2024 - We can use pdb.set_trace() or pytest.set_trace() to invoke PDB debugger and tracing from within the code. When your code stumble across the line with pdb.set_trace() it will start tracing and you can see a pdb prompt in the command prompt.
Find elsewhere
🌐
Medium
medium.com › @barudwale20 › pytest-101-lesson-5-debugging-and-troubleshooting-2e951369e417
Pytest 101: Lesson 5 - Debugging and Troubleshooting | by Shubham Barudwale | Medium
February 11, 2023 - Pytest Test Failure Reporting with --tbOption: The --tb option is used to control the output of tracebacks in Pytest. Tracebacks are a representation of the call stack at the time of a test failure.
🌐
SeleniumBase
seleniumbase.com › home › the ultimate pytest debugging guide
The ultimate pytest debugging guide - SeleniumBase
June 25, 2022 - Calling "pdb.set_trace()" or "ipdb.set_trace()" from your test after importing "pdb" or "ipdb" respectively. (Python versions 3.7+ and newer can also use the "breakpoint()" method to enter Debug Mode.) When Debug Mode is activated, the browser window will remain open (when used in combination with browser automation), and you can see how variables look from the command-line. (Note that you may need to add "-s" to your "pytest" run command to allow breakpoints, unless you already have a "pytest.ini" file present with "addops = --capture=no" in it.)
🌐
O'Reilly
oreilly.com › library › view › python-testing-with › 9781680502848 › f_0032.xhtml
Python Testing with pytest - Python Testing with pytest [Book]
September 15, 2017 - Tracing Fixture Execution with –setup-show If you run the test from the last section, you don’t get to see what fixtures are run:​ ​$ ​​cd​​ ​​/path/to/code/​​ ​$ ​​pip​​... - Selection from Python Testing with pytest [Book]
Author   Brian Okken
Published   2017
Pages   222
🌐
GitHub
github.com › pytest-dev › pytest › issues › 7640
Showing stack traces on KeyboardInterrupt · Issue #7640 · pytest-dev/pytest
August 12, 2020 - topic: reportingrelated to terminal ... ... Right now, the default behavior of pytest when you keyboard interrupt it is to hide the traceback, and print a message saying that you can show it with --full-trace....
Author   asmeurer
🌐
GitHub
github.com › pytest-dev › pytest › issues › 3823
Option '--trace' doesn't work with module 'unittest' · Issue #3823 · pytest-dev/pytest
August 17, 2018 - Thanks first for adding option '--trace'. That's very helpful to me. I tried it and it does work with test functions. However, it doesn't work with tests based on python unittest module, e.g. import unittest class TestFoo(unittest.TestCase): def test_1(self): assert True ... bash-4.4$ pytest --trace tmp/test1.py ============================================================ test session starts ============================================================ platform linux -- Python 3.6.5, pytest-3.7.1, py-1.5.3, pluggy-0.7.1 rootdir: /data/data/com.termux/files/home, inifile: plugins: interactive-0.1.4 collected 1 item tmp/test1.py .
Author   guocb
🌐
GitHub
github.com › microsoft › playwright-python › issues › 2365
Why does executing pytest --tracing on in some code not produce the trace.zip file and also delete the existing test-results directory · Issue #2365 · microsoft/playwright-python
March 20, 2024 - Why does executing pytest --tracing on in some code not produce the trace.zip file and also delete the existing test-results directory#2365
Author   aiyisuizhongqi
🌐
pytest
docs.pytest.org › en › 7.2.x › how-to › failures.html
How to handle test failures — pytest documentation
When tests are complete, the system will default back to the system Pdb trace UI. With --pdb passed to pytest, the custom internal Pdb trace UI is used with both breakpoint() and failed tests/unhandled exceptions.
🌐
pytest
docs.pytest.org › en › 7.1.x › how-to › output.html
Managing pytest’s output — pytest documentation
pytest --showlocals # show local variables in tracebacks pytest -l # show local variables (shortcut) pytest --tb=auto # (default) 'long' tracebacks for the first and last # entry, but 'short' style for the other entries pytest --tb=long # exhaustive, informative traceback formatting pytest --tb=short # shorter traceback format pytest --tb=line # only one line per failure pytest --tb=native # Python standard library formatting pytest --tb=no # no traceback at all
🌐
GitHub
gist.github.com › weissjeffm › 8690186
pytest trace · GitHub
August 16, 2018 - pytest trace. GitHub Gist: instantly share code, notes, and snippets.
🌐
PyPI
pypi.org › project › pytctracer
pytctracer · PyPI
April 26, 2024 - PyTCTracer is a test-to-code traceability approach and library, which allows for dynamic code tracing of Python repositories using the Pytest testing framework, and automatic generation of test-to-code traceability links from the trace data ...
      » pip install pytctracer
    
Published   Apr 26, 2024
Version   0.2.4
🌐
Python Basics
python-basics-tutorial.readthedocs.io › en › latest › test › pytest › debug.html
Debugging test failures - Python Basics
use the --pdb option. With --pdb, pytest will stop at the point of failure. uses the combination of the --lf and --trace options.