如何在诗歌中使用 nox?

Yoh*_*hei 6 python pytest python-poetry

我想在我用诗歌管理的项目中使用nox

不顺利的是在 nox 会话中安装 dev 依赖项。

我有noxfile.py如下所示:

import nox
from nox.sessions import Session
from pathlib import Path

__dir__ = Path(__file__).parent.absolute()


@nox.session(python=PYTHON)
def test(session: Session):
    session.install(str(__dir__))  # I want to use dev dependency here
    session.run("pytest")
Run Code Online (Sandbox Code Playgroud)

如何在 nox 会话中安装开发依赖项?

Yan*_*ann 5

目前session.install不支持poetryinstall仅在 shell 中运行 pip 。您可以poetry使用更通用的方法来激活session.run

例子:

@nox.session(python=False)
def tests(session):
    session.run('poetry', 'shell')
    session.run('poetry', 'install')
    session.run('pytest')
Run Code Online (Sandbox Code Playgroud)

当您设置会话时,您可以通过自己禁用 python virtualenv ( python=False) 的创建并激活poetry的 来完成所有操作poetry shell

  • 从版本 2019.11.9 开始, `nox` 自动将 `VIRTUAL_ENV` 传递给](https://github.com/theacodes/nox/pull/245) `poetry` 或 `pipenv`,因此 `poetry` 可以使用由 nox 创建的虚拟环境。 (2认同)