Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

You can simple send the results to a file

python -m unittest discover -p "*.py" > output.txt

If you need another format, there are a variety of packages: See this previous question For example unittest-xml-reporting will give JUnit style output for e.g. a CI server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top