nose icon indicating copy to clipboard operation
nose copied to clipboard

Nose doesn't run in python3.9 alpha version

Open fruch opened this issue 4 years ago • 16 comments

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'   

fruch avatar Dec 03 '19 06:12 fruch

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

jszakmeister avatar Dec 06 '19 01:12 jszakmeister

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

fruch avatar Dec 11 '19 07:12 fruch

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

tdhopper avatar Jan 22 '20 18:01 tdhopper

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 avatar Jan 22 '20 22:01 ngoldbaum

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.

ngoldbaum avatar Jan 22 '20 22:01 ngoldbaum

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.

hugovk avatar Jan 23 '20 11:01 hugovk

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

fruch avatar Jan 26 '20 10:01 fruch

@fruch or alternatively do pip install nose-py3

atsb avatar Feb 06 '20 20:02 atsb

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.

The Do not use binary packages workaround doesn't work in windows, nosetests executable can be found, Is there other workaround? C:>nosetests 'nosetests' is not recognized as an internal or external command, operable program or batch file.

tudu123 avatar Aug 30 '22 07:08 tudu123

You could try downloading nose-1.3.7.tar.gz from https://pypi.org/project/nose/#files and then pip install nose-1.3.7.tar.gz, or try https://pypi.org/project/nose-py3/, but it's definitely time to migrate to pytest.

hugovk avatar Aug 30 '22 08:08 hugovk

@hugovk I got the same issue today. I found the answer alone. Just replace

nosetests --with-doctest .\tests\doctests.py --verbose

with

python -m pytest --doctest-modules -v .\folder_that_contain_your_code

Where .\folder_that_contain_your_code is your clone. Not your doctest.py

Best reguards.

gogo2464 avatar Sep 02 '22 21:09 gogo2464

Fixed in master, but otherwise:

import collections
try:
    collections.Callable
except AttributeError:
    import collections.abc
    collections.Callable = collections.abc.Callable

dirkf avatar Sep 25 '22 22:09 dirkf

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).

collimarco avatar Nov 30 '22 13:11 collimarco

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):

Sgrgeto avatar Apr 20 '23 16:04 Sgrgeto

Just use nose-py3 instead

atsb avatar Apr 20 '23 18:04 atsb

Or: https://github.com/nose-devs/nose/issues/1099#issuecomment-1257294641

dirkf avatar Apr 21 '23 13:04 dirkf