我正在学习 IBM 的 DevOps 和软件工程课程,在其中一个实验室中,我应该使用
nosetests
工具运行一些测试。本实验设计为在虚拟环境中完成,但我宁愿在我的 PC 上本地运行它。
我克隆了 git 存储库并使用
nosetests
安装了 pip3 install nose
。然后我进入测试所在的根文件夹但没有成功:
我尝试用以下方法运行它:
nosetests
python3 nosetests
/Library/Frameworks/Python.framework/Versions/3.11/bin/nosetests
但它们都不起作用。
他们给出以下错误消息:
zsh: command not found: nosetests
/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 3.11 不支持nosetests。建议迁移到PyTest。
如果人们仍然需要使用
nose
,它已在 pynose
中针对较新版本的 Python 进行了修补:
https://pypi.org/project/pynose/
pip install pynose
,然后您可以使用 pynose
或 nosetests
运行测试。
与旧版
pynose
相比,nose
的变化包括:
flake8
中的所有 nose
问题。imp
模块替换 importlib
模块。-s
选项始终处于活动状态以查看print()
的输出。--co
作为使用 --collect-only
的快捷方式。使用
pip install pynose
运行此命令后出现此错误,
鼻子测试
工作正常