I use next command to run my tests:
python -m unittest discover -p "*.py"
It writes test's result to stdout. But I would like get result as file (if possible in html) Now I get it using PyCharm and it works perfectly but I need to run tests on remote machines automatically and get report of course. How can I do it?
You can write the output into a file using >
:
python -m unittest discover -p "*.py" > results.txt
This is not Python specific but UNIX which allows you to redirect standard output to a file (which is what > filename
does).
Basically you have to subclass the TestRunner
class and write your own output implementation (If a stdout redirection isn't what you have in mind).
A basic overview of the included unittest machination from another answer.
In principle a TestRunner
uses the provided information of your TestSuite
and stores it's results into a TestResult
object. Each class can be modified to your suits.
An example for a HTMLTestRuner from Wai Yip Tung.
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