Marc Mailhot
Marc Mailhot

Reputation: 480

Calling and gathering results from py.test from within code

I'm working on a system that needs to be able to test python files with py.test, and use the output (what tests passed and failed) within the program. Is there anyway to call py.test from within python, tell it to run the testing code in [name].py on the code in [otherName].py, and have it return the results of the test?

Upvotes: 5

Views: 2400

Answers (1)

Alex Okrushko
Alex Okrushko

Reputation: 7372

I think you are looking for Calling pytest from Python code at Usage and Invocations page.

Also limiting tests to the specific file could be done by Specifying tests / selecting tests.

In other words, this should do the trick:

pytest.main(['my_test_file.py'])

P.S.: Py.test Documantation is pretty good, you can find most of the answers there ;).

Upvotes: 3

Related Questions