简体   繁体   中英

Parametrized test is skipped in pytest

Why the following parametrized test get skipped when running with pytest from command line? It doesn't happen when running from 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. Instead of using ../data relative to current directory, try to make it fixed based on something else (eg location of this script).

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM