I want to completely custom tests results output.
In unittest I can implement my own test runner by example of unittest.TextTestRunner. How can I do the same in pytest?
-
Take a look at how pytest-custom-report plugin does it for inspiration.wim– wim2024-06-06 04:43:04 +00:00Commented Jun 6, 2024 at 4:43
Add a comment
|
1 Answer
As described in "Writing plugins" section of pytest documentation, you'll need to work with pytest hooks:
pytestimplements all aspects of configuration, collection, running and reporting by calling well specified hooks of the following plugins:
Also see:
- py.test code snippets
- pycon tutorial session (it also goes through using hooks)
3 Comments
Gill Bates
Seems like hooks allows to just modify information that will be represented in some standard way, but how to completely redesign results report? For example I want to write it to CSV?
Jason Antman
Gill, that's certainly possible, as far as I know. For an example, look at Mozilla Web QA's pytest module, which formats reports as HTML. A lot of the logic would be the same as formatting them as CSV (though IMO using standard JUnit XML would be a lot better...) github.com/davehunt/pytest-mozwebqa/tree/master/pytest_mozwebqa