braindecode icon indicating copy to clipboard operation
braindecode copied to clipboard

Can we get rid of code executed when importing test module?

Open robintibor opened this issue 4 years ago • 3 comments
trafficstars

Regarding https://github.com/braindecode/braindecode/blob/e7063545e7462fb50e216d7cd31020b36ae4d521/test/unit_tests/datautil/test_preprocess.py#L18-L26

Wonder if the figures that do deepcopy couldn't call another fixture that has module level like https://github.com/braindecode/braindecode/blob/master/test/unit_tests/samplers/test_samplers.py#L22-L34?

Seems nicer to me to not have code that executes on import

robintibor avatar Jun 15 '21 12:06 robintibor

what do you mean it's execute on import? it should executed when you start pytest

agramfort avatar Jun 15 '21 15:06 agramfort

I mean in this code, the dataset and window creation is done on module level, so when test_preprocess.py is imported it would be executed: https://github.com/braindecode/braindecode/blob/e7063545e7462fb50e216d7cd31020b36ae4d521/test/unit_tests/datautil/test_preprocess.py#L18-L26

Don't know if this really causes any problems, but seems slightly unclean? like this may not be the way pytest expects as well?

robintibor avatar Jun 16 '21 11:06 robintibor

We could instantiate the objects in session-level fixtures, and have function-level fixtures that do the deepcopy like here: https://stackoverflow.com/questions/53193932/how-to-avoid-mutating-objects-from-session-scope-fixtures-in-pytest

hubertjb avatar Jun 16 '21 12:06 hubertjb