vendredi 6 mai 2016

Displaying single line progress during Django management command and disabling it during tests

I have some Django management commands which call methods in other classes to perform various tasks, like fetching data from external APIs.

In those methods I'm outputting a single line that displays progress, something like:

print('Fetched %d of %d' % (n, total) + ' '*30, end='\r')

That works fine, but when I run my tests this gets printed out and screws up the .....E....F... display. I could patch print in all my tests, but that seems clunky.

So (a) should I be outputting that progress line some other way, and/or (b) is there a better way to suppress that output while running tests?

Aucun commentaire:

Enregistrer un commentaire