Как вы запускаете pytest или flask8 из powershell? - PullRequest
1 голос
/ 03 апреля 2020

Я пытаюсь запустить конвейер для проекта python. Я не могу запустить задачу pytest или колбу8.

У меня есть следующие сценарии:

  - 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

1 Ответ

0 голосов
/ 04 апреля 2020

Используйте

$ pipenv run pytest ...

, когда вы не в интерактивной оболочке (например, при вызове pytest на сервере CI). Это запустит команду в виртуальной среде pipenv. То же самое относится к poetry:

$ poetry run pytest ...

вызывает pytest в виртуальной среде, управляемой poetry.

...