Nosetests is not running for some reason

1.2k Views Asked by At

I'm going through the course of IBM for DevOps and Software Engineering and in one of the labs, I'm supposed to run some tests with the nosetests tool. This lab was designed to be done in a virtual environment, but I'd rather run it locally on my PC.

I cloned the git repo and installed nosetests with pip3 install nose. Then after I go to the root folder where the tests are located but with no success:

I tried to run it with the following methods:

  1. nosetests
  2. python3 nosetests
  3. /Library/Frameworks/Python.framework/Versions/3.11/bin/nosetests

but none of them work.

they give the following error messages:

  1. zsh: command not found: nosetests

  2. /Library/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python: can't open file '/Users/georgiangelov/devops-school/duwjx-tdd_bdd_PracticeCode/labs/01_running_tests_with_nose/nosetests': [Errno 2] No such file or directory

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/bin/nosetests", line 8, in <module>
    sys.exit(run_exit())
             ^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/nose/core.py", line 118, in __init__
    unittest.TestProgram.__init__(
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/main.py", line 101, in __init__
    self.parseArgs(argv)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/nose/core.py", line 179, in parseArgs
    self.createTests()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/nose/core.py", line 193, in createTests
    self.test = self.testLoader.loadTestsFromNames(self.testNames)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/nose/loader.py", line 481, in loadTestsFromNames
    return unittest.TestLoader.loadTestsFromNames(self, names, module)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 220, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 220, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/nose/loader.py", line 454, in loadTestsFromName
    return LazySuite(
           ^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/nose/suite.py", line 53, in __init__
    super(LazySuite, self).__init__()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/suite.py", line 22, in __init__
    self._tests = []
    ^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/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'
3

There are 3 best solutions below

0
angelov_georgi On

Turns out that nosetests is not supported for python 3.11. It's recommended to migrate to PyTest.

Nose is unmaintained and no longer works with Python 3.10 #1148

0
Michael Mintz On

If people still need to use nose, it's been patched for newer versions of Python in pynose: https://pypi.org/project/pynose/

pip install pynose, then you can run tests with pynose or nosetests.

Changes in pynose from legacy nose include:

  • Fixes "AttributeError: module 'collections' has no attribute 'Callable'."
  • Fixes "AttributeError: module 'inspect' has no attribute 'getargspec'."
  • Fixes "ImportError: cannot import name '_TextTestResult' from 'unittest'."
  • Fixes "RuntimeWarning: TestResult has no addDuration method."
  • Fixes all flake8 issues from the original nose.
  • Replaces the imp module with the newer importlib module.
  • The default logging level now hides "debug" logs for less noise.
  • The -s option is always active to see the output of print().
  • Adds --co as a shortcut to using --collect-only.
0
Shaho Rezaie On

use pip install pynose I got this error after run this command ,

nosetest

worked correctly