py.test 테스트를 실행하도록 PyCharm을 어떻게 구성합니까?
파이썬 코드에 대한 단위 테스트 작성을 시작하고 싶습니다 .py.test 프레임 워크는 Python의 번들 unittest 보다 나은 방법으로 들립니다 . 프로젝트에 "tests"디렉토리를 추가하고 test_sample.py 를 추가 했습니다. 이제 "tests"디렉토리에서 모든 테스트를 실행하도록 PyCharm을 구성하려고합니다.
PyCharm 은 테스트 러너에서 py.test 를 지원 한다고 합니다 . 테스트를 실행하기 위해 실행 / 디버그 구성 을 생성 할 수 있어야 하며 PyCharm에는 py.test 전용 "구성 생성"대화 상자 가 있다고 합니다. 그러나 그것은 주제에 대한 문서의 전체 범위이며,이 주장 된 대화 상자를 어디에서도 찾을 수 없습니다.
내가 프로젝트 도구 창에서 디렉터리를 마우스 오른쪽 단추로 클릭하면 내가있어 가정 에 "만들기 <이름>"메뉴 항목을 볼 수 있지만, 유일한 메뉴 항목은 "실행 구성 만들기"는 "만들기"로 시작. 아마도 문서가 잘못되었을 수도 있고 "실행 구성 만들기"가 유망한 것처럼 들립니다. 불행히도, 하위 메뉴의 유일한 두 항목은 "C : \ mypath ...의 Unittests"와 "C : \ mypath ...의 Doctests"입니다. 둘 다 적용되지 않습니다. unittest 나 doctest를 사용하지 않습니다. py.test에 대한 메뉴 항목이 없습니다.
test_sample.py를 열고 편집기 창에서 마우스 오른쪽 버튼을 클릭하면 "Create <name>"메뉴 항목이 약속됩니다. "test_sa에서 'Unittests 생성 ...'..."과 "Run 'test_sa에서 단위 테스트 ...' '및' 'test_sa에서 단위 테스트 ...'디버그. 다시 말하지만, 이는 모두 단위 테스트 프레임 워크에 고유합니다. py.test에는 없습니다.
"unittest"라는 메뉴 항목을 시도하면 "이름", "유형", "폴더"및 "패턴"이있는 "테스트"그룹 상자 및 "스크립트"및 "클래스"옵션이있는 대화 상자가 나타납니다. "및"함수 "등. 이것은 Python Unit Test에 대한 구성 을 추가하기 위한 대화 상자로 문서화 된 것과 정확히 같 으며"이름 "및"테스트 실행 "및"키워드 "옵션과는 다릅니다. 에서 py.test에 대한 구성 대화 상자를 표시합니다. 대화 상자 안에 추가 할 테스트 프레임 워크를 전환하는 것은 없습니다.
Python 3.1.3 및 pytest 2.0.3이 설치된 Windows에서 PyCharm 1.5.2를 사용하고 있습니다. py.test
명령 줄에서 테스트를 성공적으로 실행할 수 있으므로 pytest가 올바르게 설치되지 않는 것과 같은 간단한 것은 아닙니다.
py.test 테스트를 실행하도록 PyCharm을 어떻게 구성합니까?
파일 | 설정 | 도구 | Python 통합 도구 및 기본 테스트 실행기를 py.test로 변경하십시오. 그런 다음 py.test 옵션을 사용하여 단위 테스트 대신 테스트를 만듭니다.
PyCharm 2017.3
Preference -> Tools -> Python integrated Tools
- 선택py.test
으로Default test runner
.- Django를 사용하는 경우
Preference -> Languages&Frameworks -> Django
-눈금을 설정하십시오.Do not use Django Test runner
- 에서 기존의 모든 테스트 구성을
Run/Debug configuration
지우십시오. 그렇지 않으면 이전 구성으로 테스트가 실행됩니다. - 기본 추가 인수를 설정하려면 py.test 기본 구성을 업데이트하십시오.
Run/Debug Configuration -> Defaults -> Python tests -> py.test -> Additional Arguments
툴바에서 Run / Debug Configuration 항목을 사용해야한다고 생각합니다. 이를 클릭하고 '구성 편집'을 클릭하십시오 (또는 메뉴 항목 Run-> Edit Configurations 사용). 왼쪽 창의 'Defaults'섹션에는 원하는 것이라 생각하는 'py.test'항목이 있습니다.
또한 매뉴얼이 UI와 일치하지 않는다는 것을 알았습니다. 문제를 올바르게 이해하고 도움이되기를 바랍니다.
다음은 pytest 3.7.2
(pip를 통해 설치됨) 및 pycharms에서 작동시키는 방법입니다 2017.3
.
- 이동
edit configurations
- 새로운 실행 구성을 추가하고 선택
py.test
- In the run config details, you need to set
target
=python
and the unnamed field below totests
. It looks like this is the name of your test folder. Not too sure tough. I also recommend the-s
argument so that if you debug your tests, the console will behave properly. Without the argument pytest captures the output and makes the debug console buggy.
- My tests folder looks like that. This is just below the root of my project (
my_project/tests
).
- My
foobar_test.py
file: (no imports needed):
def test_foobar(): print("hello pytest") assert True
- Run it with the normal run command
It's poorly documented to be sure. Once you get add a new configuration from defaults, you will be in the realm of running the "/Applications/PyCharm CE.app/Contents/helpers/pycharm/pytestrunner.py" script. It's not documented and has its own ideas of command line arguments.
You can:
- Try to play around, reverse the script, and see if you can somehow get py.test to accept arguments. It might work; it didn't in the first half hour for me.
- Just run "py.test *.py" from a console.
Oddly, you will find it hard to find any discussion as JetBrains does a good job of bombing Google algorithms with its own pages.
find this thread when I hit the same question and found the solution pycharm version:2017.1.2 go to "Preferences" -> "Tools" -> "Python Integrated Tools" and set the default test runner from right side panel as py.test solve my problem
I'm using 2018.2
I do Run -> Edit Configurations... Then click the + in the upper left of the modal dialog. Select "python tests" -> py.test Then I give it a name like "All test with py.test"
I select Target: module name and put in the module where my tests are (that is 'tests' for me) or the module where all my code is if my tests are mixed in with my code. This was tripping me up.
I set the Python interpreter.
I set the working directory to the project directory.
With a special Conda python setup which included the pip install for py.test plus usage of the Specs addin (option --spec) (for Rspec like nice test summary language), I had to do ;
1.Edit the default py.test to include option= --spec , which means use the plugin: https://github.com/pchomik/pytest-spec
2.Create new test configuration, using py.test. Change its python interpreter to use ~/anaconda/envs/ your choice of interpreters, eg py27 for my namings.
3.Delete the 'unittests' test configuration.
4.Now the default test config is py.test with my lovely Rspec style outputs. I love it! Thank you everyone!
p.s. Jetbrains' doc on run/debug configs is here: https://www.jetbrains.com/help/pycharm/2016.1/run-debug-configuration-py-test.html?search=py.test
With 2018.3 it appears to automatically detect that I'm using pytest, which is nice, but it still doesn't allow running from the top level of the project. I had to run pytest
for each tests
directory individually.
However, I found that I could choose one of the configurations and manually edit it to run at the root of the project and that this worked. I have to manually choose it in the Configurations drop-down - can't right click on the root folder in the Project pane. But at least it allows me to run all tests at once.
참고URL : https://stackoverflow.com/questions/6397063/how-do-i-configure-pycharm-to-run-py-test-tests
'Programing' 카테고리의 다른 글
파이썬 2.7 사용자 입력 받기 및 따옴표없이 문자열로 조작 (0) | 2020.06.20 |
---|---|
github (시간 / 일)의“실제”커밋 날짜 참조 (0) | 2020.06.20 |
C # 목록. 내림차순 (0) | 2020.06.20 |
IEnumerable에서 첫 번째 요소를 얻는 방법 (0) | 2020.06.20 |
mysql 클라이언트 (Linux) 만 설치하는 방법이 있습니까? (0) | 2020.06.20 |