Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nose doesn't run in python3.9 alpha version #1099

Open
fruch opened this issue Dec 3, 2019 · 16 comments
Open

Nose doesn't run in python3.9 alpha version #1099

fruch opened this issue Dec 3, 2019 · 16 comments

Comments

@fruch
Copy link

fruch commented Dec 3, 2019

Traceback (most recent call last):                                                                                                                                     
  File "/usr/lib/python3.9/runpy.py", line 193, in _run_module_as_main                                                                                                  
    return _run_code(code, main_globals, None,                                                                                                                          
  File "/usr/lib/python3.9/runpy.py", line 86, in _run_code                                                                                                             
    exec(code, run_globals)                                                                                                                                             
  File "/home/fruch/Projects/scylla-dtest/.venv39/lib/python3.9/site-packages/nose/__main__.py", line 8, in <module>                                                    
    run_exit()                                                                                                                                                         
  File "/home/fruch/Projects/scylla-dtest/.venv39/lib/python3.9/site-packages/nose/core.py", line 118, in __init__                                                     
    unittest.TestProgram.__init__(              
  File "/usr/lib/python3.9/unittest/main.py", line 100, in __init__                                                                                  
    self.parseArgs(argv)                              
  File "/home/fruch/Projects/scylla-dtest/.venv39/lib/python3.9/site-packages/nose/core.py", line 179, in parseArgs                          
    self.createTests()                                 
  File "/home/fruch/Projects/scylla-dtest/.venv39/lib/python3.9/site-packages/nose/core.py", line 193, in createTests                                                   
    self.test = self.testLoader.loadTestsFromNames(self.testNames)                                                                                                        File "/home/fruch/Projects/scylla-dtest/.venv39/lib/python3.9/site-packages/nose/loader.py", line 481, in loadTestsFromNames                                          
    return unittest.TestLoader.loadTestsFromNames(self, names, module)                                                                                                 
  File "/usr/lib/python3.9/unittest/loader.py", line 220, in loadTestsFromNames                                                                                        
    suites = [self.loadTestsFromName(name, module) for name in names]                                       
  File "/usr/lib/python3.9/unittest/loader.py", line 220, in <listcomp>                                                                                                
    suites = [self.loadTestsFromName(name, module) for name in names]                                                                        
  File "/home/fruch/Projects/scylla-dtest/.venv39/lib/python3.9/site-packages/nose/loader.py", line 454, in loadTestsFromName                                          
    return LazySuite(                                                                                                                                                  
  File "/home/fruch/Projects/scylla-dtest/.venv39/lib/python3.9/site-packages/nose/suite.py", line 53, in __init__                                                     
    super(LazySuite, self).__init__()                                                                                                        
  File "/usr/lib/python3.9/unittest/suite.py", line 22, in __init__                                                                                                         self._tests = []                                                                                                                        
  File "/home/fruch/Projects/scylla-dtest/.venv39/lib/python3.9/site-packages/nose/suite.py", line 106, in _set_tests                                    
    if isinstance(tests, collections.Callable) and not is_suite:                                                                                       
AttributeError: module 'collections' has no attribute 'Callable'   
@jszakmeister
Copy link
Contributor

FYI: nose is no longer maintained. You should look to migrate to nose2, though it's a different paradigm than the original nose.

@fruch
Copy link
Author

fruch commented Dec 11, 2019

nice, more reason to move to pytest.
@roydahan FYI

@tdhopper
Copy link

Where is if isinstance(tests, collections.Callable) and not is_suite: coming from? I don't see it in suite.py.

@ngoldbaum
Copy link

I believe that's coming from a transformation that's being applied by an old version of 2to3, see e.g. https://docs.python.org/3.4/library/2to3.html#2to3fixer-callable. I guess the python3 wheel for nose on pypi was generated using python3.4 or older. The transformation applied by 2to3 was updated in python3.5.

@ngoldbaum
Copy link

ngoldbaum commented Jan 22, 2020

I suspect that if you tried building a nose wheel from the sdist tarball using a recent python3 version and installed the resulting wheel that would work. Haven't tried it. However pip install nose will be broken forever unless someone does a release since pip will always try to grab the python3 wheel that's on pypi for the last release.

@hugovk
Copy link

hugovk commented Jan 23, 2020

Good find! This works for me on Python 3.9, to prevent installation from wheel:

pip install -U nose --no-binary :all:

Full example:

$ pip install -U nose
Collecting nose
  Using cached nose-1.3.7-py3-none-any.whl (154 kB)
Installing collected packages: nose
Successfully installed nose-1.3.7
$ cat test.py
def test():
    assert True
$ nosetests
Traceback (most recent call last):
  File "/Users/hugo/.pyenv/versions/3.9-dev/bin/nosetests", line 8, in <module>
    sys.exit(run_exit())
  File "/Users/hugo/.pyenv/versions/3.9-dev/lib/python3.9/site-packages/nose/core.py", line 118, in __init__
    unittest.TestProgram.__init__(
  File "/Users/hugo/.pyenv/versions/3.9-dev/lib/python3.9/unittest/main.py", line 100, in __init__
    self.parseArgs(argv)
  File "/Users/hugo/.pyenv/versions/3.9-dev/lib/python3.9/site-packages/nose/core.py", line 179, in parseArgs
    self.createTests()
  File "/Users/hugo/.pyenv/versions/3.9-dev/lib/python3.9/site-packages/nose/core.py", line 193, in createTests
    self.test = self.testLoader.loadTestsFromNames(self.testNames)
  File "/Users/hugo/.pyenv/versions/3.9-dev/lib/python3.9/site-packages/nose/loader.py", line 481, in loadTestsFromNames
    return unittest.TestLoader.loadTestsFromNames(self, names, module)
  File "/Users/hugo/.pyenv/versions/3.9-dev/lib/python3.9/unittest/loader.py", line 220, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/Users/hugo/.pyenv/versions/3.9-dev/lib/python3.9/unittest/loader.py", line 220, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/Users/hugo/.pyenv/versions/3.9-dev/lib/python3.9/site-packages/nose/loader.py", line 454, in loadTestsFromName
    return LazySuite(
  File "/Users/hugo/.pyenv/versions/3.9-dev/lib/python3.9/site-packages/nose/suite.py", line 53, in __init__
    super(LazySuite, self).__init__()
  File "/Users/hugo/.pyenv/versions/3.9-dev/lib/python3.9/unittest/suite.py", line 22, in __init__
    self._tests = []
  File "/Users/hugo/.pyenv/versions/3.9-dev/lib/python3.9/site-packages/nose/suite.py", line 106, in _set_tests
    if isinstance(tests, collections.Callable) and not is_suite:
AttributeError: module 'collections' has no attribute 'Callable'
$ pip uninstall -y nose
Found existing installation: nose 1.3.7
Uninstalling nose-1.3.7:
  Successfully uninstalled nose-1.3.7
$ pip install -U nose --no-binary :all:
Collecting nose
  Using cached nose-1.3.7.tar.gz (280 kB)
Skipping wheel build for nose, due to binaries being disabled for it.
Installing collected packages: nose
    Running setup.py install for nose ... done
Successfully installed nose-1.3.7
$ nosetests
.
----------------------------------------------------------------------
Ran 1 test in 0.013s

OK
$

I'd still recommend migrating to pytest, but this is a quick fix.

@fruch
Copy link
Author

fruch commented Jan 26, 2020

thanks @hugovk, this anyhow would be a good incentive to move to pytest...

@atsb
Copy link

atsb commented Feb 6, 2020

@fruch or alternatively do pip install nose-py3

jwilk added a commit to jwilk-archive/python-djvulibre that referenced this issue Mar 1, 2021
pukkandan added a commit to yt-dlp/yt-dlp that referenced this issue Jul 23, 2021
`nosetests` is no longer being maintained : nose-devs/nose#1099
and will stop working in py 3.10 as can be seen in #480
@collimarco
Copy link

On my MacOS + Homebrew the problem was present because I was calling python3 setup.py test instead of python3.9 setup.py test (which works).

sbraz added a commit to sbraz/rmlint that referenced this issue Jan 3, 2023
nose is no longer maintained, see
nose-devs/nose#1099 (comment).

This commit switches to pytest.

Amongst the changes, here are the most relevant ones:
* Create a conftest.py that contains fixtures.
* Replace nose.with_setup with yield fixtures.
* Use pytest.skip instead of print and nose.plugins.skip.SkipTest.
* Use pytest.mark.slow instead of nose.plugins.attrib.attr("slow").
* Use pytest.mark.parametrize instead of parameterized, simplify
  parametrized tests that use both `shell` and `inverse_order`.
* Update Travis config.
* Update SConscript.
* Update documentation.
sbraz added a commit to sbraz/rmlint that referenced this issue Jan 3, 2023
nose is no longer maintained, see
nose-devs/nose#1099 (comment).

This was initially submitted here: https://bugs.gentoo.org/878695.

This commit switches to pytest.

Amongst the changes, here are the most relevant ones:
* Create a conftest.py that contains fixtures.
* Replace nose.with_setup with yield fixtures.
* Use pytest.skip instead of print and nose.plugins.skip.SkipTest.
* Use pytest.mark.slow instead of nose.plugins.attrib.attr("slow").
* Use pytest.mark.parametrize instead of parameterized, simplify
  parametrized tests that use both `shell` and `inverse_order`.
* Update Travis config.
* Update SConscript.
* Update documentation.
TomSmithCGAT added a commit to CGATOxford/UMI-tools that referenced this issue Feb 27, 2023
Removes 3.10 which is incompatible with nose (nose-devs/nose#1099 & #546)
@Sgrgeto
Copy link

Sgrgeto commented Apr 20, 2023

You should do this, the problem is that the module collections doesnt have the attribute Callable, to call Callable you should before this line collections.abc.Callable.
The important thing is that are three or two lines that you should do this modificaction on the nose.py file so you need to go to this path AppData/Local/Programs/Python/Python311/Lib/site-packages/nose
Change the permission of the file to exectuable then
change the lines of code 541 and 458 the lines are
if isinstance(tests, collections.Callable) or isinstance(tests, unittest.TestSuite):
instead to run the program correctly write this line
if isinstance(tests, collections.abc.Callable) or isinstance(tests, unittest.TestSuite):

@atsb
Copy link

atsb commented Apr 20, 2023

Just use nose-py3 instead

@dirkf
Copy link

dirkf commented Apr 21, 2023

Or: #1099 (comment)

Szelethus added a commit to Szelethus/codechecker that referenced this issue May 30, 2023
-> Motivation, why pytest

Nose is no longer supported, it is not compatible with python3.9, and
will never be:
nose-devs/nose#1099 (comment)

As python3.10 is the oldest python version available from
Ubuntu22.04's package manager by default, it is time to migrate.

We never really relied on many nose features (as far as I can tell, we
never actually import anything from the nose package), this change isn't
particularly painful (don't let the size of the change fool you, its
pretty much just moving code around!). Pytest seems to be the industry
standard framework lately, and supports most nose constructs out of the box.

The aim of this change that from the make target side, nothing changed
-- you still analyzer tests with 'make analyzer', a specific test file
with (having 'functional/skip' as the example):

'TEST=tests/functional/skip make test_analyzer_feature'

This is basically how granular nose could get. If you wanted to run a
specific test case in a test file, you couldn't do that, but you can
with pytest:

pytest analyzer/tests/functional/skip -v -k test_analyze_header_with_file_option

Mind that there are many environmental variables that needs to be set
in addition to the above command, so we need to write new make targets
to make this user-friendly, but nevertheless, it is possible.

-> What changed

Broadly speaking, the change can be divided into 4 parts:

1. Replacing nose with pytest in the makefiles
2. Replacing nose config files with pytest files
3. Replace `setup_package`/`teardown_package` with
   `setup_class`/`teardown_class`, and `setup`/`teardown` to
   `setup_method` and `teardown_method`.
4. Fix up individual test environments under `analyzer/tools`.

For the Makefile and config changes, I hope they are self explanatory.
Pytest is a rather painless drop-in replacement on the invocation side.

On the conversion, there is a page that discusses how one can convert
nose to pytest:
https://docs.pytest.org/en/7.1.x/how-to/nose.html
It is stated (and is true) that pytest supports most, but not quite all
features in nose. `{setup, teardown}_package` is not supported, but it
turns out that we dedicate a package to every test class, so simply
switching to `{setup, teardown}_class` was sufficient. That accounts for
the vast majority of the code change. That is the only meaningful
structural change -- `setup`->`setup_method` and the teardown variant
was really just a simple rename.

At last, you can notice that some `__init__.py` files are copied over
from `analyzer/test/__init__.py`. Frankly, I'm not sure how the tests
worked previously without these files setting up these variables
properly, but this skeleton fell out of the closet now.
Szelethus added a commit to Szelethus/codechecker that referenced this issue May 30, 2023
-> Motivation, why pytest

Nose is no longer supported, it is not compatible with python3.9, and
will never be:
nose-devs/nose#1099 (comment)

As python3.10 is the oldest python version available from
Ubuntu22.04's package manager by default, it is time to migrate.

We never really relied on many nose features (as far as I can tell, we
never actually import anything from the nose package), this change isn't
particularly painful (don't let the size of the change fool you, its
pretty much just moving code around!). Pytest seems to be the industry
standard framework lately, and supports most nose constructs out of the box.

The aim of this change that from the make target side, nothing changed
-- you still analyzer tests with 'make analyzer', a specific test file
with (having 'functional/skip' as the example):

'TEST=tests/functional/skip make test_analyzer_feature'

This is basically how granular nose could get. If you wanted to run a
specific test case in a test file, you couldn't do that, but you can
with pytest:

pytest analyzer/tests/functional/skip -v -k test_analyze_header_with_file_option

Mind that there are many environmental variables that needs to be set
in addition to the above command, so we need to write new make targets
to make this user-friendly, but nevertheless, it is possible.

-> What changed

Broadly speaking, the change can be divided into 4 parts:

1. Replacing nose with pytest in the makefiles
2. Replacing nose config files with pytest files
3. Replace `setup_package`/`teardown_package` with
   `setup_class`/`teardown_class`, and `setup`/`teardown` to
   `setup_method` and `teardown_method`.
4. Fix up individual test environments under `analyzer/tools`.

For the Makefile and config changes, I hope they are self explanatory.
Pytest is a rather painless drop-in replacement on the invocation side.

On the conversion, there is a page that discusses how one can convert
nose to pytest:
https://docs.pytest.org/en/7.1.x/how-to/nose.html
It is stated (and is true) that pytest supports most, but not quite all
features in nose. `{setup, teardown}_package` is not supported, but it
turns out that we dedicate a package to every test class, so simply
switching to `{setup, teardown}_class` was sufficient. That accounts for
the vast majority of the code change. That is the only meaningful
structural change -- `setup`->`setup_method` and the teardown variant
was really just a simple rename.

At last, you can notice that some `__init__.py` files are copied over
from `analyzer/test/__init__.py`. Frankly, I'm not sure how the tests
worked previously without these files setting up these variables
properly, but this skeleton fell out of the closet now.
Szelethus added a commit to Szelethus/codechecker that referenced this issue May 30, 2023
-> Motivation, why pytest

Nose is no longer supported, it is not compatible with python3.9, and
will never be:
nose-devs/nose#1099 (comment)

As python3.10 is the oldest python version available from
Ubuntu22.04's package manager by default, it is time to migrate.

We never really relied on many nose features (as far as I can tell, we
never actually import anything from the nose package), this change isn't
particularly painful (don't let the size of the change fool you, its
pretty much just moving code around!). Pytest seems to be the industry
standard framework lately, and supports most nose constructs out of the box.

The aim of this change that from the make target side, nothing changed
-- you still analyzer tests with 'make analyzer', a specific test file
with (having 'functional/skip' as the example):

'TEST=tests/functional/skip make test_analyzer_feature'

This is basically how granular nose could get. If you wanted to run a
specific test case in a test file, you couldn't do that, but you can
with pytest:

pytest analyzer/tests/functional/skip -v -k test_analyze_header_with_file_option

Mind that there are many environmental variables that needs to be set
in addition to the above command, so we need to write new make targets
to make this user-friendly, but nevertheless, it is possible.

-> What changed

Broadly speaking, the change can be divided into 4 parts:

1. Replacing nose with pytest in the makefiles
2. Replacing nose config files with pytest files
3. Replace `setup_package`/`teardown_package` with
   `setup_class`/`teardown_class`, and `setup`/`teardown` to
   `setup_method` and `teardown_method`.
4. Fix up individual test environments under `analyzer/tools`.

For the Makefile and config changes, I hope they are self explanatory.
Pytest is a rather painless drop-in replacement on the invocation side.

On the conversion, there is a page that discusses how one can convert
nose to pytest:
https://docs.pytest.org/en/7.1.x/how-to/nose.html
It is stated (and is true) that pytest supports most, but not quite all
features in nose. `{setup, teardown}_package` is not supported, but it
turns out that we dedicate a package to every test class, so simply
switching to `{setup, teardown}_class` was sufficient. That accounts for
the vast majority of the code change. That is the only meaningful
structural change -- `setup`->`setup_method` and the teardown variant
was really just a simple rename.

At last, you can notice that some `__init__.py` files are copied over
from `analyzer/test/__init__.py`. Frankly, I'm not sure how the tests
worked previously without these files setting up these variables
properly, but this skeleton fell out of the closet now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests