[TIP] how can I find in TestCase whether runs verbosely?

Robert Collins robertc at robertcollins.net
Sun Feb 17 15:29:03 PST 2013


On 18 February 2013 08:47, Matěj Cepl <mcepl at redhat.com> wrote:
> Hi,
>
> I would like to make my unittest testsuite to drop some intermediate
> test results when it is run with -v in the verbose mode. How can I find
> out in the TestCase object, that the run is verbose?

Can I ask why?

Background:
The idea is that there are two completely separate(*) things happening :
Tests are running
Something is showing the result of those tests to users.

Then, the tests should give all data to the result all the time, and
the result can choose whether to show a particular thing or not (and
how to do so - write to XML, print to screen, submit to a web
server...)

So having tests be aware of verbosity is a layering issue that would
make test code more complex and reduce the freedom of results to do
$whatever they want - unless they advertise verbose mode always and
then report less verbose later :)

For a concrete example of this sort of separation, look at
disttrial/py.test in distributed mode or testrepository, all of which
have quite separate actual reporting from where the tests are
happening.

I have a new result protocol that allows a lot more and fixes a number
of issues that turn up in practice in draft -
https://github.com/rbtcollins/testtools/tree/streamresult - so if we
need to add verbosity feedback to it, this would be the right time to
do so, before I get to the PEP stage).

So I'm guessing you have something you want to do, but I'm not sure
why the test case needs to know.

-Rob

-- 
Robert Collins <rbtcollins at hp.com>
Distinguished Technologist
HP Cloud Services



More information about the testing-in-python mailing list