Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 961
Marc Mailhot Avatar asked Oct 21 '22 16:10

Marc Mailhot


1 Answers

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

like image 107
Alex Okrushko Avatar answered Oct 24 '22 07:10

Alex Okrushko