dzieciou
dzieciou

Reputation: 4524

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?

Upvotes: 0

Views: 82

Answers (1)

nicolas
nicolas

Reputation: 3290

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 (e.g. 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)

Upvotes: 1

Related Questions