[英]pytest or py.test, and inconsistent documentation
我決定試一試。
Virtualenv已啟動(python 3.5.2)pip install -U pytest(根據: https ://docs.pytest.org/en/latest/getting-started.html)。
下一個文檔說我應該運行:
$ pytest --version
This is pytest version 3.x.y, imported from $PYTHON_PREFIX/lib/python3.6/site-packages/pytest.py
但這實際上是我得到的:
$ pytest --version
Usage: pytest [OPTIONS] [testfile [testpattern]]
examples:
pytest path/to/mytests.py
pytest path/to/mytests.py TheseTests
pytest path/to/mytests.py TheseTests.test_thisone
pytest path/to/mytests.py -m '(not long and database) or regr'
pytest one (will run both test_thisone and test_thatone)
pytest path/to/mytests.py -s not (will skip test_notthisone)
pytest: error: no such option: --version
但是如果我運行:
py.test --version
This is pytest version 3.9.1, imported from ${HOME}/${V_ENV}/lib/python3.5/site-packages/pytest.py
根據那個答案:
py.test是舊( deprecated
他們說)和pytest的路要走。
我檢查了兩個:
$ which pytest
$HOME/$V_ENV/bin/pytest
$ which py.test
$HOME/$V_ENV/bin/py.test
完全相同的文件。
$ HOME是我的家,但是$ V_ENV是我保留虛擬機的地方(我使用virtualenvwrapper)。
運行測試時:
有用:
$ py.test tests/
它不(例外):
$ pytest tests/
我檢查了堆棧跟蹤。
py.test使用python3運行(正確)pytest使用python2運行(不正確,來自操作系統)
有人知道發生了什么嗎?
看起來py.test和pytest完全一樣,因此不使用py.test的概念似乎已經過時了。 我說的對嗎?
碰巧py安裝在系統python庫中(可能是某種東西的另一個依賴項)。 有一致的方法來重現該錯誤。 它涉及以下步驟。
而且它將保持這種方式。 但是,如果您停用並激活env或完全關閉外殼並重新打開它,它將對其進行修復。
===舊Anwer ===
感謝@hoefling,他為我推了個正確的方向!
有一個名為py的舊庫,已作為tox的依賴項安裝。 在與安裝和/或運行這兩個庫相關的某些情況下,您可能會發現安裝損壞。 最初,我認為這完全是安裝順序(先安裝tox,然后再進行pytest),但我無法重現該命令。 因此,當前的工作原理是,我先運行Tox導致它創建無效的virtualenv,然后安裝了損壞了PYTHONPATH或PATH的pytest。
簡而言之。 如果您的pytest是從頭開始的,那么有一種方法可以破壞您的pytest!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.