簡體   English   中英

pytest沒有找到測試

[英]pytest doesn't find the test

我試着用這樣的斷言語句做一個簡單的測試

def sqr(x):
    return x**2 + 1 

def test_sqr():
    assert kvadrat(2) == 4

! pytest

然后它回來了

在此輸入圖像描述

如果有人有任何想法可能是錯的。

要使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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM