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

Robert Collins robertc at robertcollins.net
Mon Feb 18 02:02:24 PST 2013


On 18 February 2013 22:01, Matěj Cepl <mcepl at redhat.com> wrote:
> On 18/02/13 00:29, Robert Collins wrote:

> Maybe what I need is --debug mode.
>
> I am trying (as my lame attempt to commemorate Aaron Swartz) to make
> html2text.py (http://luther.ceplovi.cz/git/html2text.git) fully tested
> and working on Python 2.4-3.3 (both inclusive). Generally the tests are
> in a simple manner (I know, it is not the best possible manner of
> testing, but complete rewrite of the test suite is something I would
> rather avoid) ... take a HTML file, run it through the process, and
> compare the result with stored text file (actually, it is a Markdown) by
> plain self.assertEqual.
>
> You are right that for normal running of the test suite (to make sure,
> that nothing has been broken) both in verbose and non-verbose mode, it
> is probably best to leave the things as they are, but now when I am
> debugging some really intricate case, it might be useful (and maybe not,
> and I should use pdb more) to let the test suite to spit out generated
> text files for deeper analysis.
>
> What do you think?

In testtools you can just do
self.addDetail('logfile', content_from_file('foo.log'))

and this will be shown in errors (and is preserved via subunit and so forth).

https://testtools.readthedocs.org/en/latest/for-test-authors.html#a-realistic-example
for docs (note that this is showing the plumbing, not the convenience
API I show in this email).

To me this is a clear case of 'emit it always and let the consumer
decide what to do'.

-Rob

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



More information about the testing-in-python mailing list