I'm looking at switching our Django project's tests to use Pytest and pytest-django. The problem I've run into is that I can no longer cleanly halt a test run in the middle.
The default Django test runner has nice support for this:
If you press Ctrl-C while the tests are running, the test runner will wait for the currently running test to complete and then exit gracefully. During a graceful exit the test runner will output details of any test failures, report on how many tests were run and how many errors and failures were encountered, and destroy any test databases as usual. Thus pressing Ctrl-C can be very useful if you forget to pass the --failfast option, notice that some tests are unexpectedly failing and want to get details on the failures without waiting for the full test run to complete.
If you do not want to wait for the currently running test to finish, you can press Ctrl-C a second time and the test run will halt immediately, but not gracefully. No details of the tests run before the interruption will be reported, and any test databases created by the run will not be destroyed.
Is there any support for this in Pytest or pytest-django? I've done some digging, and it looks like you'd have to call unittest.installHandler()
, then somehow tell Pytest to halt the run.
With Pytest, pressing Ctrl+C just halts the test immediately without any tear down. Calling installHandler()
means that it doesn't stop the run.