Run trace.py with pytest
Asked Answered
L

1

3

I'm trying to get coverage using trace.py when running pytest. I know that pytest has its own coverage plugin pytest-cov but restrictions (number of times each line is executed is unavailable) do not allow me to use that right now. The same for coverage.py

I'm trying this command: python3.4 -m trace -c -m -C . pytest test_script.py

test_script.py:

class TestScript():
    def test_print(self):
        print ('Hello')

The output is:

nikhilh$ python3.4 -m trace -c -m -C . pytest test_script.py
pytest: Cannot run file 'pytest' because: [Errno 2] No such file or directory: 'pytest'

trace.py obviously expects a file in its arguments and not another module. How can I modify this command to get trace.py working with pytest?

Edit: I was able to find a way to get this done

nikhilh$ python3.4 -m trace -c -m -C . <pytest_script_absolute_path> test_script.py

Lambda answered 11/12, 2017 at 6:50 Comment(3)
I realize its been a bit since you posted this but could you make your solution an answer?Dissolute
Does this answer your question? How do I run python's trace with pytest?Talbot
@Talbot yep, that answer is what I came up with too.Lambda
L
2

Came across David's comment, so here's the answer that I used at that time:

python3.4 -m trace -c -m -C . <pytest_script_absolute_path> test_script.py

Lambda answered 31/3, 2020 at 20:37 Comment(2)
Where can I find the pytest_script_absolute_path? I assume this means the script that is called when running pytest from terminal...Rafa
Just followed the link above and was reminded of which pytest (or where pytest on Windows)Rafa

© 2022 - 2024 — McMap. All rights reserved.