gammapy icon indicating copy to clipboard operation
gammapy copied to clipboard

Better use of fixtures in gammapy tests

Open luca-giunti opened this issue 2 years ago • 3 comments

Reminder to make a better use of fixtures, which allow to shorten and speed up the tests. Here are a few ideas.

1.In many tests (e.g. here, here and here) the spectrum_dataset fixture defined in gammapy/conftest.py could be used instead of simulating/creating new datasets. Perhaps this could work also for onoff datasets using SpectrumDatasetOnOff.from_spectrum_dataset(spectrum_dataset) 2. Also for MapDataset and other frequently used objects, we could define a fixture under gammapy/conftest.py and always reuse it 3. We could speed up the tests by changing the scope of the dataset fixtures to "session", so that they are created only once (see related TODO). But for this to work all tests should be adapted in such a way that they don't modify the datasets in place. I suspect this would be a painful PR

If you agree with some of these ideas, I could work on them.

luca-giunti avatar Mar 09 '22 10:03 luca-giunti

Thanks @luca-giunti, I agree this would be very nice clean up work for the tests! In terms of code organisation we could maybe introduce a dedicated fixture.py file per sub-package and then import all into the global conftest.py namespace.

adonath avatar Mar 11 '22 23:03 adonath

Good idea! When I find the time I can perhaps work on this

luca-giunti avatar Mar 17 '22 10:03 luca-giunti

@registerrier I think the structure of the tests is not a priority for v1.0. However it should be after v1.0, so we will establish the API and feature completeness for v1.0 and then we improve the tests against it, before we move on with adding significant new features...

adonath avatar Jul 27 '22 13:07 adonath