python / python/cpython

Add a decorator to run a test in an isolated subprocess

Abierto
#152,548 0 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

tests type-feature
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Feature or enhancement

Some tests need to run in a fresh interpreter, isolated from the rest of the test run: they mutate process-global or interpreter state that would leak into (or be polluted by) other tests, depend on a clean interpreter startup, or may crash the interpreter outright. Today this has to be done ad hoc per test (spawning a child via script_helper, hand-rolling the result reporting), which is verbose and inconsistent.

I propose a decorator that runs a test in a dedicated subprocess and reports the result transparently, so the test reads like any other:

class MyTest(unittest.TestCase):
    @isolated()
    def test_global_state(self):
        ...

It would start in test.support and could later move to unittest.

Proposed behaviour

  • @isolated() decorates a test method (only that method runs in a subprocess) or a whole TestCase subclass (the whole class runs in a single subprocess, so setUpClass()/setUpModule() run once there).
  • Failures, errors and skips — including those of individual subTest()s — are reported for the corresponding test, and show the original subprocess traceback.
  • A setUpClass()/setUpModule() failure or skip in the subprocess is reported for the whole class.
  • The subprocess inherits the parent's regrtest configuration (enabled resources -u, memory limit -M, verbosity -v, failfast), so requires_resource(), requires(), bigmemtest() and similar behave the same in both processes.
  • A running_isolated flag is true while running in the subprocess, so setUp()/tearDown() and the class- and module-level fixtures can choose what to run there.

Linked PRs

Linked PRs
  • gh-152551
  • gh-152565
  • gh-152570
  • gh-152639
  • gh-154780
  • gh-154783
  • gh-154784
  • gh-155162
  • gh-155163
  • gh-155167
  • gh-155168
  • gh-155169
  • gh-155230
  • gh-155231
  • gh-155238

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con el punto de entrada test.support y el manejo existente de subprocess en script_helper. Revisa los pull requests enlazados junto con el comportamiento propuesto del decorador, incluido su uso con métodos y TestCase, la notificación de resultados, la configuración heredada de regrtest y running_isolated. Se considera completado cuando los fallos, omisiones, fixtures, subTests y tracebacks de subprocess especificados se notifican de forma transparente.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
testing
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.