Jon*_*den 13 python windows pytest
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
Run Code Online (Sandbox Code Playgroud)
我是在有效的 pytest 框架中运行还是在框架之外运行并不重要。我卸载了 pytest 和 python,然后重新安装,结果相同。我尝试运行“python -m pytest”并得到相同的结果。我运行的是 Windows 10、python 3.8 或 3.9。我缺少什么?
这是使用调试标志的一些附加输出
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
Run Code Online (Sandbox Code Playgroud)
日志文件相当大,所以我会仔细检查一下是否有任何内容跳出。
好吧,这很有趣:
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]
Run Code Online (Sandbox Code Playgroud)
这条线在做什么:
perform_collect <Session empty_directory exitstatus=<ExitCode.OK: 0>
testsfailed=0 testscollected=0> ['and', 'level1'] [collection]
Run Code Online (Sandbox Code Playgroud)
也许这就是它得到“和”的地方。这一行引起了我的注意,因为我的一个 pytest 框架中有一个名为“level1”的标记。但我不在该目录中,因此它可能不相关。
如果我切换到我的 macbook 并在空目录中运行 pytest,该行看起来像:
perform_collect <Session temp exitstatus=<ExitCode.OK: 0>
testsfailed=0 testscollected=0> ['/Users/jhayden/temp'] [collection]
Run Code Online (Sandbox Code Playgroud)
这就是我运行的空目录。
我还尝试在 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
Run Code Online (Sandbox Code Playgroud)
我终于明白了。我设置了这个环境变量:
PYTEST_ADDOPTS=-m 网络和 level1
不久前我正在尝试使用环境变量,但在重新启动之前从未遇到过问题。希望这可以帮助将来的人不要成为像我这样的白痴,哈哈。
| 归档时间: |
|
| 查看次数: |
26831 次 |
| 最近记录: |