简体   繁体   English

如何从 powershell 运行 pytest 或 flask8?

[英]How do you run pytest or flask8 from powershell?

I am trying to run a pipeline on python project.我正在尝试在 python 项目上运行管道。 I am not able to run the pytest task nor the flask8.我无法运行 pytest 任务和 flask8。

I have the following scripts:我有以下脚本:

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

giving the following output:给出以下 output:

 $ 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

Why can't I run the py.test?为什么我不能运行 py.test? I have tried the following command as well python -m py.test我也尝试过以下命令python -m py.test

Use利用

$ pipenv run pytest ...

when you are not in an interactive shell (eg when invoking pytest on a CI server).当您不在交互式 shell 中时(例如,在 CI 服务器上调用pytest时)。 This will run the command in pipenv 's virtual environment.这将在pipenv的虚拟环境中运行命令。 The same applies to poetry :这同样适用于poetry

$ poetry run pytest ...

invokes pytest in the virtual environment managed by poetry .poetry管理的虚拟环境中调用pytest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM