gammapy
gammapy copied to clipboard
Better use of fixtures in gammapy tests
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.
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.
Good idea! When I find the time I can perhaps work on this
@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...