Python Poetry 的默认测试对我不起作用
Python Poetry's default test not working for me
我想尝试诗歌,但最初的 setup/test 不适合我,所以我有点困惑。我相信它应该 'just work',所以我想我错过了一些简单的步骤?
我在 macOS 上:12.3 (21E230)
我安装了最新版本:
$ poetry --version
Poetry version 1.1.13
现在我只想要一个纯香草设置,并验证基础工作:
$ poetry new poetry_demo --src
Created package poetry_demo in poetry_demo
$ cd poetry_demo/
$ poetry install
Creating virtualenv poetry-demo in /Users/barryredmond/dev/git/poetry_demo/.venv
Updating dependencies
Resolving dependencies... (0.1s)
Writing lock file
Package operations: 8 installs, 0 updates, 0 removals
• Installing pyparsing (3.0.8)
• Installing attrs (21.4.0)
• Installing more-itertools (8.13.0)
• Installing packaging (21.3)
• Installing pluggy (0.13.1)
• Installing py (1.11.0)
• Installing wcwidth (0.2.5)
• Installing pytest (5.4.3)
Installing the current project: poetry_demo (0.1.0)
$ poetry check
All set!
我认为这应该让我设置好?让 运行 内置测试:
$ poetry run pytest
================================================================================================ test session starts =================================================================================================
platform darwin -- Python 3.10.4, pytest-5.4.3, py-1.11.0, pluggy-0.13.1
rootdir: /Users/barryredmond/dev/git/poetry_demo
collected 0 items / 1 error
======================================================================================================= ERRORS =======================================================================================================
_____________________________________________________________________________________ ERROR collecting tests/test_poetry_demo.py _____________________________________________________________________________________
.venv/lib/python3.10/site-packages/py/_path/local.py:704: in pyimport
__import__(modname)
<frozen importlib._bootstrap>:1027: in _find_and_load
???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:688: in _load_unlocked
???
.venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:143: in exec_module
source_stat, co = _rewrite_test(fn, self.config)
.venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:330: in _rewrite_test
co = compile(tree, fn, "exec", dont_inherit=True)
E TypeError: required field "lineno" missing from alias
============================================================================================== short test summary info ===============================================================================================
ERROR tests/test_poetry_demo.py - TypeError: required field "lineno" missing from alias
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================================================================== 1 error in 0.05s ==================================================================================================
并且只是为了验证设置是否适合任何查看此内容的人:
$ tree
.
├── README.rst
├── poetry.lock
├── pyproject.toml
├── src
│ └── poetry_demo
│ └── __init__.py
└── tests
├── __init__.py
├── __pycache__
│ └── __init__.cpython-310.pyc
└── test_poetry_demo.py
4 directories, 7 files
.
$ cat tests/test_poetry_demo.py
from poetry_demo import __version__
def test_version():
assert __version__ == '0.1.0'
.
$ cat src/poetry_demo/__init__.py
__version__ = '0.1.0'
我也试过没有 --src
但还是一样。
poetry
在使用 poetry new
时包含的 pytest
版本已过时,不适用于 python3.10。您必须将 pytest
更新为 poetry add --dev pytest@latest
。
从poetry 1.2开始,poetry在通过poetry new
初始化项目时不再定义任何默认依赖。
我想尝试诗歌,但最初的 setup/test 不适合我,所以我有点困惑。我相信它应该 'just work',所以我想我错过了一些简单的步骤?
我在 macOS 上:12.3 (21E230) 我安装了最新版本:
$ poetry --version
Poetry version 1.1.13
现在我只想要一个纯香草设置,并验证基础工作:
$ poetry new poetry_demo --src
Created package poetry_demo in poetry_demo
$ cd poetry_demo/
$ poetry install
Creating virtualenv poetry-demo in /Users/barryredmond/dev/git/poetry_demo/.venv
Updating dependencies
Resolving dependencies... (0.1s)
Writing lock file
Package operations: 8 installs, 0 updates, 0 removals
• Installing pyparsing (3.0.8)
• Installing attrs (21.4.0)
• Installing more-itertools (8.13.0)
• Installing packaging (21.3)
• Installing pluggy (0.13.1)
• Installing py (1.11.0)
• Installing wcwidth (0.2.5)
• Installing pytest (5.4.3)
Installing the current project: poetry_demo (0.1.0)
$ poetry check
All set!
我认为这应该让我设置好?让 运行 内置测试:
$ poetry run pytest
================================================================================================ test session starts =================================================================================================
platform darwin -- Python 3.10.4, pytest-5.4.3, py-1.11.0, pluggy-0.13.1
rootdir: /Users/barryredmond/dev/git/poetry_demo
collected 0 items / 1 error
======================================================================================================= ERRORS =======================================================================================================
_____________________________________________________________________________________ ERROR collecting tests/test_poetry_demo.py _____________________________________________________________________________________
.venv/lib/python3.10/site-packages/py/_path/local.py:704: in pyimport
__import__(modname)
<frozen importlib._bootstrap>:1027: in _find_and_load
???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:688: in _load_unlocked
???
.venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:143: in exec_module
source_stat, co = _rewrite_test(fn, self.config)
.venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:330: in _rewrite_test
co = compile(tree, fn, "exec", dont_inherit=True)
E TypeError: required field "lineno" missing from alias
============================================================================================== short test summary info ===============================================================================================
ERROR tests/test_poetry_demo.py - TypeError: required field "lineno" missing from alias
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================================================================== 1 error in 0.05s ==================================================================================================
并且只是为了验证设置是否适合任何查看此内容的人:
$ tree
.
├── README.rst
├── poetry.lock
├── pyproject.toml
├── src
│ └── poetry_demo
│ └── __init__.py
└── tests
├── __init__.py
├── __pycache__
│ └── __init__.cpython-310.pyc
└── test_poetry_demo.py
4 directories, 7 files
.
$ cat tests/test_poetry_demo.py
from poetry_demo import __version__
def test_version():
assert __version__ == '0.1.0'
.
$ cat src/poetry_demo/__init__.py
__version__ = '0.1.0'
我也试过没有 --src
但还是一样。
poetry
在使用 poetry new
时包含的 pytest
版本已过时,不适用于 python3.10。您必须将 pytest
更新为 poetry add --dev pytest@latest
。
从poetry 1.2开始,poetry在通过poetry new
初始化项目时不再定义任何默认依赖。