﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31509	Enable faulthandler automatically during tests	Adam Johnson	nobody	"Sometimes when testing one discovers a ""hang,"" segfault, or other issue. This can be hard to diagnose since default test output just includes dots, so one can't tell which test has hung. Also hangs can be random, so hard to diagnose.

In such cases, [https://docs.python.org/3/library/faulthandler.html faulthandler] is useful to enable, as killing the process will output a stack trace for each thread.

Tests can be run using faulthandler with `python -X faulthandler manage.py test`. However this needs both knowledge that it exists, and re-running the tests, when the hang might be non-deterministic.

Pytest [https://docs.pytest.org/en/latest/usage.html?highlight=faulthandler#fault-handler automatically enables faulthandler] and provides the option to disable it. I suggest we replicate the same in Django's `DiscoverRunner` - call `faulthandler.enable()` at the start of tests, unless disabled with a flag `--no-faulthandler`.

Searching for past issues, it seems we've had three tickets where faulthandler was recommended for diagnosis: https://code.djangoproject.com/search?q=faulthandler . Additionally there are probably other cases where no progress was made on a bug because of lack of `faulthandler` knowledge."	New feature	new	Testing framework	dev	Normal				Unreviewed	0	0	0	0	1	0
