Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python unittest results file

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?

like image 317
Eugene Avatar asked Jan 11 '23 17:01

Eugene


2 Answers

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

like image 166
Simeon Visser Avatar answered Jan 18 '23 22:01

Simeon Visser


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.

like image 33
Don Question Avatar answered Jan 18 '23 23:01

Don Question