pytest一直在为我工作。今天,重新启动后,它抛出这个错误:
PS C:\> pytest
================================================= test session starts =================================================
platform win32 -- Python 3.9.1, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: C:\
plugins: forked-1.3.0, html-3.1.1, metadata-1.11.0, xdist-2.2.0
collected 0 items
================================================ no tests ran in 0.01s ================================================
ERROR: file or directory not found: and
不管我是在一个有效的pytest框架中运行还是在框架之外运行。我卸载了pytest和python,然后重新安装,结果相同。我试着运行“python -m pytest”,结果相同。我正在运行Windows 10,Python 3。8还是3.9我漏掉了什么
下面是使用debug标志的一些附加输出
PS C:\> mkdir empty_directory
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 1/14/2021 8:23 PM empty_directory
PS C:\> cd empty_directory
PS C:\empty_directory> python -m pytest -vvv --debug
writing pytestdebug information to C:\empty_directory\pytestdebug.log
================================================= test session starts =================================================
platform win32 -- Python 3.9.1, pytest-6.2.1, py-1.10.0, pluggy-0.13.1 -- C:\Users\611528\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe
using: pytest-6.2.1 pylib-1.10.0
setuptools registered plugins:
pytest-forked-1.3.0 at C:\Users\611528\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pytest_forked\__init__.py
pytest-html-3.1.1 at C:\Users\611528\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pytest_html\plugin.py
pytest-metadata-1.11.0 at C:\Users\611528\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pytest_metadata\plugin.py
pytest-xdist-2.2.0 at C:\Users\611528\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\xdist\plugin.py
pytest-xdist-2.2.0 at C:\Users\611528\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\xdist\looponfail.py
cachedir: .pytest_cache
metadata: {'Python': '3.9.1', 'Platform': 'Windows-10-10.0.18362-SP0', 'Packages': {'pytest': '6.2.1', 'py': '1.10.0', 'pluggy': '0.13.1'}, 'Plugins': {'forked': '1.3.0', 'html': '3.1.1', 'metadata': '1.11.0', 'xdist': '2.2.0'}, 'JAVA_HOME': 'C:\\Program Files\\Java\\jdk-15.0.1'}
rootdir: C:\empty_directory
plugins: forked-1.3.0, html-3.1.1, metadata-1.11.0, xdist-2.2.0
collected 0 items
================================================ no tests ran in 0.04s ================================================
wrote pytestdebug information to C:\empty_directory\pytestdebug.log
ERROR: file or directory not found: and
日志文件相当大,所以我将检查它,看看是否有什么跳出来。
好吧,这很有趣:
finish pytest_sessionstart --> [] [hook]
pytest_collection [hook]
session: <Session empty_directory exitstatus=<ExitCode.OK: 0> testsfailed=0 testscollected=0>
perform_collect <Session empty_directory exitstatus=<ExitCode.OK: 0> testsfailed=0 testscollected=0> ['and', 'level1'] [collection]
pytest_collection_finish [hook]
session: <Session empty_directory exitstatus=<ExitCode.OK: 0> testsfailed=0 testscollected=0>
pytest_report_collectionfinish [hook]
config: <_pytest.config.Config object at 0x0000025C74701FD0>
startdir: C:\empty_directory
items: []
finish pytest_report_collectionfinish --> [] [hook]
finish pytest_collection_finish --> [] [hook]
pytest_sessionfinish [hook]
session: <Session empty_directory exitstatus=<ExitCode.USAGE_ERROR: 4> testsfailed=0 testscollected=0>
exitstatus: ExitCode.USAGE_ERROR
pytest_terminal_summary [hook]
terminalreporter: <_pytest.terminal.TerminalReporter object at 0x0000025C74C0F550>
exitstatus: ExitCode.USAGE_ERROR
config: <_pytest.config.Config object at 0x0000025C74701FD0>
finish pytest_terminal_summary --> [] [hook]
finish pytest_sessionfinish --> [] [hook]
pytest_unconfigure [hook]
config: <_pytest.config.Config object at 0x0000025C74701FD0>
finish pytest_unconfigure --> [] [hook]
这条线是干什么的:
perform_collect <Session empty_directory exitstatus=<ExitCode.OK: 0>
testsfailed=0 testscollected=0> ['and', 'level1'] [collection]
也许这就是它得到“和”的地方。这一行引起了我的注意,因为我在我的一个pytest框架中有一个名为“level 1”的标记。但我不在那个目录里所以可能没有关联。
如果我切换到我的macbook并在一个空目录中运行pytest,那一行看起来像:
perform_collect <Session temp exitstatus=<ExitCode.OK: 0>
testsfailed=0 testscollected=0> ['/Users/jhayden/temp'] [collection]
这就是我运行的空目录。
我也试着在venv里跑步:
C:\venvs>python -m venv aaa
C:\venvs>cd aaa\Scripts
C:\venvs\aaa\Scripts>.\activate.bat
(aaa) C:\venvs\aaa\Scripts>pip install pytest
Collecting pytest
Using cached pytest-6.2.1-py3-none-any.whl (279 kB)
Collecting py>=1.8.2
Using cached py-1.10.0-py2.py3-none-any.whl (97 kB)
Collecting colorama; sys_platform == "win32"
Using cached colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Collecting packaging
Using cached packaging-20.8-py2.py3-none-any.whl (39 kB)
Collecting toml
Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
Collecting iniconfig
Using cached iniconfig-1.1.1-py2.py3-none-any.whl (5.0 kB)
Collecting atomicwrites>=1.0; sys_platform == "win32"
Using cached atomicwrites-1.4.0-py2.py3-none-any.whl (6.8 kB)
Collecting pluggy<1.0.0a1,>=0.12
Using cached pluggy-0.13.1-py2.py3-none-any.whl (18 kB)
Collecting attrs>=19.2.0
Using cached attrs-20.3.0-py2.py3-none-any.whl (49 kB)
Collecting pyparsing>=2.0.2
Using cached pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
Installing collected packages: py, colorama, pyparsing, packaging, toml, iniconfig, atomicwrites, pluggy, attrs, pytest
Successfully installed atomicwrites-1.4.0 attrs-20.3.0 colorama-0.4.4 iniconfig-1.1.1 packaging-20.8 pluggy-0.13.1 py-1.10.0 pyparsing-2.4.7 pytest-6.2.1 toml-0.10.2
WARNING: You are using pip version 20.2.3; however, version 20.3.3 is available.
You should consider upgrading via the 'c:\venvs\aaa\scripts\python.exe -m pip install --upgrade pip' command.
(aaa) C:\venvs\aaa\Scripts>pytest
================================================= test session starts =================================================
platform win32 -- Python 3.9.1, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: C:\venvs\aaa\Scripts
collected 0 items
================================================ no tests ran in 0.01s ================================================
ERROR: file or directory not found: and
3条答案
按热度按时间inkz8wg91#
我终于想通了。我设置了这个环境变量:
PYTEST_ADDOPTS=-m个网络和level 1
前一段时间我在试验env变量,但在重新启动之前从未出现过问题。希望这能帮助将来的人不要像我这样白痴,哈哈。
kse8i1jr2#
我也遇到了同样的问题,最后通过导航到Pytest测试文件夹的当前路径来解决这个问题。
例如:
tests是包含测试文件的文件夹
测试
|--test_01.py
|--test_02.py
我在终端改变了路径:“C:...\path_to_test”
然后,运行命令:pytest test_01.派
t40tm48m3#
对于任何人停止和面临同样的问题时,使用标记(e。g.
pytest -m "not your-mark"
)请注意(至少对于我在Windows-CMD上),双引号是必需的!
使用单引号将失败,并出现上述错误,但是
双引号则不会。