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?
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 ;).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With