Nosetests 由于某种原因未运行。

huangapple go评论83阅读模式
英文:

Nosetests is not running for some reason

问题

我在IBM的DevOps和软件工程课程中进行学习,在其中一个实验中,我需要使用nosetests工具运行一些测试。该实验设计为在虚拟环境中完成,但我更愿意在我的个人电脑上本地运行。

我克隆了git仓库并使用pip3 install nose安装了nosetests。然后,我前往测试所在的根目录,但没有成功:

我尝试了以下方法来运行它:

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

但都没有成功。

它们给出了以下错误消息:

  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'
英文:

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

3.

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'

答案1

得分: 1

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

英文:

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

答案2

得分: 0

如果人们仍然需要使用 nose,则已为较新版本的Python进行了修补,可使用 pynose:https://pypi.org/project/pynose/

运行以下命令以安装 pynosepip install pynose,然后可以使用 pynosenosetests 运行测试。

pynose 与传统的 nose 相比的更改包括:

  • 修复了 "AttributeError: module 'collections' has no attribute 'Callable'."。
  • 修复了 "AttributeError: module 'inspect' has no attribute 'getargspec'."。
  • 修复了 "ImportError: cannot import name '_TextTestResult' from 'unittest'."。
  • 修复了 "RuntimeWarning: TestResult has no addDuration method."。
  • 修复了原始 nose 中的所有 flake8 问题。
  • 用较新的 importlib 模块替换了 imp 模块。
  • 默认的日志级别现在隐藏了 "debug" 日志以减少噪音。
  • -s 选项始终处于活动状态以查看 print() 的输出。
  • 添加了 --co 作为使用 --collect-only 的快捷方式。
英文:

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.

huangapple
  • 本文由 发表于 2023年6月29日 16:28:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76579315.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定