sgkit-dev / sgkit-plink

NOW ARCHIVED! PLINK IO implementations for sgkit. With https://github.com/pystatgen/sgkit/issues/65, now maintained and developed in the sgkit repo.
Apache License 2.0
0 stars 4 forks source link

Run tests that use pytest.figure #22

Open CarlKCarlK opened 4 years ago

CarlKCarlK commented 4 years ago

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 commented 4 years ago

Hey Carl,

Not at my computer so I’ll say some more tomorrow but installing the “pytest-datadir” package would fix that.

On Wed, Aug 5, 2020 at 8:11 PM Carl Kadie notifications@github.com wrote:

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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pystatgen/sgkit-plink/issues/22, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOYVMCMC7SD4BR7DOICUOLR7HYMZANCNFSM4PWA7GFA .

CarlKCarlK commented 4 years ago

That worked! Thanks (and now I see it in requirements-dev.txt)

From: Eric Czech notifications@github.com Sent: Wednesday, August 05, 2020 5:33 PM To: pystatgen/sgkit-plink sgkit-plink@noreply.github.com Cc: Carl Kadie carlk@msn.com; Author author@noreply.github.com Subject: Re: [pystatgen/sgkit-plink] Run tests that use pytest.figure (#22)

Hey Carl,

Not at my computer so I’ll say some more tomorrow but installing the “pytest-datadir” package would fix that.

On Wed, Aug 5, 2020 at 8:11 PM Carl Kadie notifications@github.com<mailto:notifications@github.com> wrote:

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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pystatgen/sgkit-plink/issues/22, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOYVMCMC7SD4BR7DOICUOLR7HYMZANCNFSM4PWA7GFA .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpystatgen%2Fsgkit-plink%2Fissues%2F22%23issuecomment-669614523&data=02%7C01%7C%7C57e71ebc3ef74d47be5808d839a03887%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637322707584894937&sdata=Cb%2FpQaYawwgw3WZDTvI7GGn1KTxb8iYSrXs7jUfuv6U%3D&reserved=0, or unsubscribehttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FABR65P7TUHEFZK2LOUSENV3R7H22JANCNFSM4PWA7GFA&data=02%7C01%7C%7C57e71ebc3ef74d47be5808d839a03887%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637322707584904933&sdata=ZyRUH7r8jCg2HaMCvdD2fVYpMiRwDtlMPMYP4XoBjog%3D&reserved=0.

eric-czech commented 4 years ago

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.