简体   繁体   English

在 pytest 中跳过参数化测试

[英]Parametrized test is skipped in pytest

Why the following parametrized test get skipped when running with pytest from command line?为什么从命令行使用pytest运行时会跳过以下参数化测试? It doesn't happen when running from Intellij IDEA.从 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):

How can I investigate that and solve it?我该如何调查并解决它?

If you get a difference, then the current directory is different when running with IntelliJ.如果您有所不同,则使用 IntelliJ 运行时当前目录不同。 Instead of using ../data relative to current directory, try to make it fixed based on something else (eg location of this script).不要使用相对于当前目录的../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