簡體   English   中英

在 pytest 中跳過參數化測試

[英]Parametrized test is skipped in pytest

為什么從命令行使用pytest運行時會跳過以下參數化測試? 從 Intellij IDEA 運行時不會發生這種情況。

def list_files(dir):
    return glob.glob(f'{dir}/*.json')

@pytest.mark.parametrize("data_fpath", list_files('../data'))
def test_schema(data_fpath):

我該如何調查並解決它?

如果您有所不同,則使用 IntelliJ 運行時當前目錄不同。 不要使用相對於當前目錄的../data而是嘗試根據其他內容(例如此腳本的位置)修復它。

def list_files(dir):
    return glob.glob(f'{dir}/*.json')

THIS_DIR = os.path.dirname(os.path.abspath(__file__))

@pytest.mark.parametrize(
    "data_fpath",
    list_files(os.path.join(THIS_DIR, '..', 'data')))
def test_schema(data_fpath):
    print(data_fpath)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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