nose-devs / nose

nose is nicer testing for python
http://readthedocs.org/docs/nose/en/latest/
1.36k stars 395 forks source link

Python 3.11: cannot import name '_TextTestResult' from 'unittest.runner' #1116

Open jwilk opened 3 years ago

jwilk commented 3 years ago

nose doesn't work with Python 3.11:

$ python3.11 -m nose
Traceback (most recent call last):
  File "/home/jwilk/.local/lib/python3.11/site-packages/nose/result.py", line 14, in <module>
    from unittest.runner import _TextTestResult
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: cannot import name '_TextTestResult' from 'unittest.runner' (/usr/local/lib/python3.11/unittest/runner.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/runpy.py", line 146, in _get_module_details
    return _get_module_details(pkg_main_name, error)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
    ^^^^^^^^^^^^^^^^^^^^
  File "/home/jwilk/.local/lib/python3.11/site-packages/nose/__init__.py", line 1, in <module>
    from nose.core import collector, main, run, run_exit, runmodule
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jwilk/.local/lib/python3.11/site-packages/nose/core.py", line 15, in <module>
    from nose.result import TextTestResult
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jwilk/.local/lib/python3.11/site-packages/nose/result.py", line 16, in <module>
    from unittest import _TextTestResult
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: cannot import name '_TextTestResult' from 'unittest' (/usr/local/lib/python3.11/unittest/__init__.py)

This seems to be caused by https://github.com/python/cpython/commit/b0a6ede3d0bd6fa4ffe413ab4dfc1059201df25b, which removes the _TextTestResult = TextTestResult alias.

mr-c commented 2 years ago

This Python 3.11 change was reverted https://github.com/python/cpython/pull/30935 (though there are other challenges running nose on Python 3.11 )

hugovk commented 2 years ago

And has been removed again for Python 3.12 (due October 2023):

$ python3.12 --version
Python 3.12.0a2
$ python3.12 -m nose
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/nose/result.py", line 14, in <module>
    from unittest.runner import _TextTestResult
ImportError: cannot import name '_TextTestResult' from 'unittest.runner' (/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/runner.py). Did you mean: 'TextTestResult'?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 189, in _run_module_as_main
  File "<frozen runpy>", line 148, in _get_module_details
  File "<frozen runpy>", line 112, in _get_module_details
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/nose/__init__.py", line 1, in <module>
    from nose.core import collector, main, run, run_exit, runmodule
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/nose/core.py", line 15, in <module>
    from nose.result import TextTestResult
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/nose/result.py", line 16, in <module>
    from unittest import _TextTestResult
ImportError: cannot import name '_TextTestResult' from 'unittest' (/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/__init__.py). Did you mean: 'TextTestResult'?