How do I run python's trace with pytest?
Asked Answered
P

2

3

I am trying to run a trace on a program that is executed with pytest. I am trying the command

python3 -m trace -t  pytest test_one.py 

but it is giving me

Cannot run file 'pytest' because: [Errno 2] No such file or directory: 'pytest'

as I am assuming trace.py is expecting a file. I saw this similar question but I'm a bit struggling to understand what is supposed to mean - is it supposed to be the executable file for pytest itself (I actually don't see where that is on my computer, I found a folder to a main.py and init.py but I can't seem to see some executable), or something else?

Palmieri answered 24/2, 2020 at 17:38 Comment(3)
Yes, that's actually the pytest executable itself. Under *nix, you should be able to localize it using which pytest, under Windows it's located under Scripts (in the virtual enviroment, or the Python installation path, depending on what you use).Hourigan
I would see this as a duplicate of the referenced question, but that one has no accepted answer (only a comment with the answer).Hourigan
which pytest on Unix is where pytest on Windows. @MrBeanBremen why not adding an answer yourself? The question is more than a year old, it's unlikely that the OP will give an answer any time soon.Arceliaarceneaux
H
3

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

Hourigan answered 24/2, 2020 at 19:35 Comment(0)
C
0

We can use the --module flag to trace pytest as a module:

python -m trace -t --module pytest -- path/to/pytests --pytest-arg

As usual, the -- signals that the remaining arguments are positional, allowing you to pass --flags or -flags to pytest.

Chalk answered 19/8, 2024 at 18:10 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.