Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Django TEST_RUNNER supports xunit xml and logging capture?

I'm attempting to set up a new django project, and I've configured TEST_RUNNER in settings.py to be django_nose.NoseTestSuiteRunner.

I chose this test runner because it seems to be the only one I can find that has the following features:

  • writes xunit xml test report
  • captures logging/stdout and only displays for failed tests.

However I've heard that nose is unmaintained and I'm having a hard time finding a suitable replacement. The standard test runner doesn't capture logging nor writes xunit as far as I'm able to tell (would love to be proven wrong!)

I run tests like so:

python -m coverage run manage.py test --noinput
python -m coverage report --include="app/*" --show-missing --fail-under=100
python -m coverage xml --include="app/*" -o ./reports/coverage.xml

With this in settings.py:

TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

And this setup.cfg:

[nosetests]
verbosity=0
with-xunit=1
xunit-file=./reports/xunit.xml
logging-clear-handlers=1

The last two lines are the real juicy bits I can't seem to find in other test runners. nose captures the logging and clears other logging handlers (eg, the handler that dumps on stdout) so the test runs output is much cleaner (you only see logging for tests that failed).

In other non-django projects I typically use nose2 but django-nose2 project appears to be 6 years old and lacking python3 support??

Please let me know which test runner is the "recommended" one (eg, most popular) with django support, thanks.

like image 663
robru Avatar asked Oct 02 '17 18:10

robru


1 Answers

I have had success with unittest-xml-reporting:

TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'

https://github.com/xmlrunner/unittest-xml-reporting#django-support

The output directory can be configured with the TEST_OUTPUT_DIR setting.

like image 115
Juuso Ohtonen Avatar answered Nov 05 '22 05:11

Juuso Ohtonen