测试
新功能 0.28.0
运行项目的测试套件。目前,这始终运行 pytest
。请注意,与在后台自动用于 linting 和格式化的 ruff
不同,pytest
必须安装到虚拟环境中。因此,要使用它,你需要将 pytest
声明为开发依赖项。
$ rye add --dev pytest
建议将测试放置在项目 src
文件夹旁边名为 tests
的文件夹中。
有关如何使用 pytest 的更多信息,请查看 Pytest 文档.
示例
运行测试套件
$ rye test
platform win32 -- Python 3.11.1, pytest-8.0.2, pluggy-1.4.0
rootdir: /Users/john/Development/stuff
plugins: anyio-4.3.0
collected 1 item
stuff/tests/test_batch.py . [100%]
参数
-
[EXTRA_ARGS]...
传递给测试运行器的额外参数。这些参数将直接转发到底层测试运行器(当前始终为
pytest
)。请注意,额外参数必须用--
标记与其他参数分开。
选项
-
-a, --all
: 测试工作区中的所有包 -
-p, --package <PACKAGE>
: 运行特定包的测试套件 -
--pyproject <PYPROJECT_TOML>
: 使用此pyproject.toml
文件 -
-v, --verbose
: 启用详细诊断 -
-q, --quiet
: 关闭所有输出 -
-i, --ignore
: 忽略指定的目录 -
-s
,--no-capture
: 为测试运行器禁用 stdout/stderr 捕获 -
-h, --help
: 打印帮助(使用“-h”查看摘要)