earthaccess icon indicating copy to clipboard operation
earthaccess copied to clipboard

Refactor loops in tests to be parametrized

Open botanical opened this issue 1 year ago • 6 comments

Some tests can be updated to use pytest.parametrize, such as https://github.com/nsidc/earthaccess/blob/main/tests/integration/test_auth.py#L83-L98

botanical avatar May 16 '24 23:05 botanical

cc @Sherwin-14

mfisher87 avatar May 21 '24 00:05 mfisher87

Hey could I get some more info about this? How can I approach this and what sort of considerations I need to take?

Sherwin-14 avatar Jun 26 '24 17:06 Sherwin-14

Hey @Sherwin-14, not 100% sure if this answers your question, but we're looking to replace the for loop in the linked test with a @pytest.parametrize decorator as shown in the docs linked in the top-level post. This will increase the total number of tests, but there will be less assertions in each of the affected test. Does this help?

mfisher87 avatar Jun 26 '24 17:06 mfisher87

Hey @Sherwin-14, not 100% sure if this answers your question, but we're looking to replace the for loop in the linked test with a @pytest.parametrize decorator as shown in the docs linked in the top-level post. This will increase the total number of tests, but there will be less assertions in each of the affected test. Does this help?

If I understand correctly, we might need to break these test functions and replace the for loop's with @pytest.parametrize decorator. This would result in 2 tests resulting from one single broken test?

Sherwin-14 avatar Jun 26 '24 17:06 Sherwin-14

There would still be one test function, but the decorator would allow that test to run multiple times with different parameters, in other words different input data and different expected outputs. With this method, we specify the test logic once in the function, and then represent the different parameters as a data structure that we pass to the @pytest.parametrize decorator.

mfisher87 avatar Jun 26 '24 17:06 mfisher87

@mfisher87 Hey can you assign me this one?

Sherwin-14 avatar Jun 28 '24 13:06 Sherwin-14

Fixed by #736

chuckwondo avatar Jul 27 '24 18:07 chuckwondo