Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Run tests that use pytest.figure #22

Open
CarlKCarlK opened this issue Aug 6, 2020 · 3 comments
Open

Run tests that use pytest.figure #22

CarlKCarlK opened this issue Aug 6, 2020 · 3 comments

Comments

@CarlKCarlK
Copy link
Collaborator

Greetings,

I just learned about pytest fixtures an hour ago. It looks cool and useful, but still don't understand what "params=[dict()]" does. Can you help me run the tests?

I'm getting error message like "E fixture 'shared_datadir' not found". I assume I need to configure something.

Thanks,
Carl

@eric-czech
Copy link
Collaborator

eric-czech commented Aug 6, 2020 via email

@CarlKCarlK
Copy link
Collaborator Author

CarlKCarlK commented Aug 6, 2020 via email

@eric-czech
Copy link
Collaborator

I just learned about pytest fixtures an hour ago. It looks cool and useful, but still don't understand what "params=[dict()]" does

To say a little more about the pytest features, I think it's easiest to try to explain these bits of code in the tests:

@pytest.fixture(params=[dict()])
def ds1(shared_datadir, request):
    path = shared_datadir / example_dataset_1
    return read_plink(path=path, bim_sep="\t", fam_sep="\t", **request.param)

def test_read_multi_path(shared_datadir, ds1):
  ...

@pytest.mark.parametrize("ds1", [dict(bim_int_contig=True)], indirect=True)
def test_read_int_contig(ds1):
  ...

The params=[dict()] part sets a default for when using indirect parameterization. Any time you have a fixture and then a variable in a test with the same name as the fixture, pytest will fill that value based on how you defined the fixture. This is most useful in a situation where the fixture represents something expensive or that needs initialize/shutdown logic, but I've been using that for building datasets used repeatedly too. @pytest.fixture(scope="module") is a useful way to make sure a fixture is only run once.

I don't know any features of pytest-datadir other than that if you use the variable name shared_datadir, pytest-datadir defines fixtures that will result in that value being filled in by an absolute path to a data folder that all tests use. If you instead call the variable datadir, a different fixture will fill in the path to a folder with the same name as the test module. For test_pysnptools.py, it would look for a folder called just pysnptools.

The pytest.mark.parameterize feature is another one we make common use of, although the use of it in those tests specifically is somewhat atypical.

Hope that helps.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants