[英]pytest doesn't find the test
要使pytest
找到測試,這些必須位於當前目錄或子目錄中的文件中,文件名必須以test
開頭(盡管可能是可自定義的)。
所以如果你使用(在Jupyter筆記本內):
%%file test_sth.py
def sqr(x):
return x**2 + 1
def test_sqr():
assert kvadrat(2) == 4
這將創建一個名為test_sth.py
的文件, test_sth.py
包含給定的內容。
然后跑! pytest
! pytest
它應該工作(好吧,失敗):
============================= test session starts =============================
platform win32 -- Python 3.6.3, pytest-3.3.0, py-1.5.2, pluggy-0.6.0
rootdir: D:\JupyterNotebooks, inifile:
plugins: hypothesis-3.38.5
collected 1 item
test_sth.py F [100%]
================================== FAILURES ===================================
__________________________________ test_sqr ___________________________________
def test_sqr():
> assert kvadrat(2) == 4
E NameError: name 'kvadrat' is not defined
test_sth.py:5: NameError
========================== 1 failed in 0.12 seconds ===========================
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.