I am doing some Selenium testing via pytest. The next step is to start doing some reporting. I'd like to write something that allows me to run the tests, collect the results and send out an email. So far the closest thing that I've found to this is writing out the test result to the result log and then use a plugin to check the exist status and send an email from there. This works but is slightly cumbersome and I'm hoping that there is a more elegant way to do it. While the overall pytest documentation is great, the plugin documentation is rather poor - I can't even find pytest_sessionfinish
anywhere, even though it appears to work.
import pytest
class MyPlugin:
def pytest_sessionfinish(self, exitstatus):
if exitstatus == 0:
#Send success email
pass
else:
#Read output.txt
#Add output.txt to email body
#Send email
pass
pytest.main("--resultlog=output.txt", plugins=[MyPlugin()])
Q: What is the best way to run and collect results from pytest?