How to use `pytest` from Python?

Viewed 23821

I'm working in a project that recently switched to the pytest unittest framework. I was used to calling my tests from Eclipse, so that I can use the debugger (e.g. placing breakpoints to analyze how a test failure develops). Now this is no longer possible, since the only way to run the tests is via the command line blackbox.

Is there some way to use pytest from within Python, so that one is not forced to drop out of the IDE? The tests should of course not be run in a separate process.

7 Answers

For me it was this:

pytest.main(["-x", "path to test file", "args"])

For example:

import pytest
pytest.main(["-x", "/api/test", "-vv"])
Related