Nosetests 由于某种原因未运行

问题描述 投票:0回答:3

我正在学习 IBM 的 DevOps 和软件工程课程,在其中一个实验室中,我应该使用

nosetests
工具运行一些测试。本实验设计为在虚拟环境中完成,但我宁愿在我的 PC 上本地运行它。

我克隆了 git 存储库并使用

nosetests
安装了
pip3 install nose
。然后我进入测试所在的根文件夹但没有成功:

我尝试用以下方法运行它:

  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'
python unit-testing pytest nose
3个回答
1
投票

事实证明,python 3.11 不支持nosetests。建议迁移到PyTest。

Nose 未维护,不再适用于 Python 3.10 #1148


0
投票

如果人们仍然需要使用

nose
,它已在
pynose
中针对较新版本的 Python 进行了修补: https://pypi.org/project/pynose/

pip install pynose
,然后您可以使用
pynose
nosetests
运行测试。

与旧版

pynose
相比,
nose
的变化包括:

  • 修复了“AttributeError:模块‘collections’没有属性‘Callable’。”
  • 修复了“AttributeError:模块‘inspect’没有属性‘getargspec’。”
  • 修复了“导入错误:无法从‘unittest’导入名称‘_TextTestResult’。”
  • 修复了“运行时警告:TestResult 没有 addDuration 方法。”
  • 修复了原始
    flake8
    中的所有
    nose
    问题。
  • 用较新的
    imp
    模块替换
    importlib
    模块。
  • 默认日志记录级别现在隐藏“调试”日志以减少噪音。
  • -s
    选项始终处于活动状态以查看
    print()
    的输出。
  • 添加
    --co
    作为使用
    --collect-only
    的快捷方式。

0
投票

使用

pip install pynose
运行此命令后出现此错误,

鼻子测试

工作正常

© www.soinside.com 2019 - 2024. All rights reserved.