`__module__` is not defined, seeming to contradict the Python Data Model.
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug report
Bug description:
The __module__ variable might not be defined.
This is an update to the original bug post. After some investigation this doesn't seem like a bug in unittest. Here's a simple test case that shows a situation where __module__ is not defined:
test_str = """
class MyClass:
pass
Derived = type("Derived", (MyClass,), {})
"""
test_ns = {}
exec(test_str, test_ns)
print("__module__ exists:", hasattr(test_ns["Derived"], "__module__"))
print("Module for drived:", test_ns["Derived"].__module__)
The original bug post is below:
The default test loader depends on __module__ being present. In rare cases it may not be. I encountered a crash when running unit tests using a Jupyter cell magic. The line should probably be:
fullName = f'%s.%s.%s' % (
testCaseClass.__module__ if hasattr(testCaseClass, "__module__") else "None", testCaseClass.__qualname__, attrname
)
This problem has cropped up in bug reports for other projects. For example:
https://github.com/ray-project/ray/issues/4758
https://gitlab.orekit.org/orekit-labs/python-wrapper/-/issues/411
Thank you for the wonderful work!
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
- gh-120957
- gh-120979
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza en Lib/unittest/loader.py#L220 y ejecuta la reproducción con exec proporcionada en Python 3.12. Comprueba cómo gestiona el cargador de pruebas predeterminado una clase sin module, y después añade o actualiza una prueba de regresión en la suite de pruebas de unittest. Se considera completado cuando el cargador ya no se bloquea y el caso de regresión pasa.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- testing-qa
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100