如何从powershell运行pytest或flask8?

问题描述 投票:1回答:1

我正在尝试在python项目上运行管道。我无法运行pytest任务或flask8。

我有以下脚本:

  - python -V
  - $env:Path += ";C:\Users\myuser\AppData\Roaming\Python\Python37\Scripts"
  - pipenv shell
  - pipenv install --dev
  - pipenv graph
  - pipenv shell

给出以下输出:

 $ python -V
 Python 3.7.6
 $ pipenv shell
 Launching subshell in virtual environment
 Windows PowerShell 
 Copyright (C) 2016 Microsoft Corporation. All rights reserved.
 PS C:\project> $ pipenv install --dev
 Installing dependencies from Pipfile.lock (aac0cc)
 To activate this projects virtualenv, run pipenv shell.
 Alternatively, run a command inside the virtualenv with pipenv run.
 $ pipenv graph
 ----
 pytest==4.6.9
 ----
 - setuptools [required: Any, installed: 46.1.3]
 $ pipenv shell
 Launching subshell in virtual environment
 Windows PowerShell 
 Copyright (C) 2016 Microsoft Corporation. All rights reserved.
 $ set PYTHONPATH=./src:./
 $ py.test
 py.test : The term 'py.test' is not recognized as the name of a cmdlet, function, script file, or 
 operable program. Check the spelling of the name, or if a path was included, verify that the path 
 is correct and try again.
 At C:\Users\myuser\AppData\Local\Temp\build_script515891919\script.ps1:221 char:1
 + py.test
 + ~~~~~~~
     + CategoryInfo          : ObjectNotFound: (py.test:String) [], CommandNotFoundException
     + FullyQualifiedErrorId : CommandNotFoundException

Uploading artifacts for failed job
00:00
 ERROR: Job failed: exit status 1

为什么我不能运行py.test?我也尝试了以下命令python -m py.test

python powershell pytest pipenv
1个回答
0
投票

使用

$ pipenv run pytest ...

[当您不在交互式外壳程序中时(例如,在CI服务器上调用pytest时)。这将在pipenv的虚拟环境中运行命令。 poetry同样适用:

$ poetry run pytest ...

在由pytest管理的虚拟环境中调用poetry

© www.soinside.com 2019 - 2024. All rights reserved.