Consolidate testing suite #179
Labels
Discussion
Discussion of a concept or implementation. Need to stay always open.
Testing
This is for testing features, writing tests or producing testing code
Summary
With @vinferrer's updates to the test suite (via #178) merged (🙌), I thought it might be worth re-visiting the test suite in a more general sense. It's evolved pretty rapidly as development has happened on
phys2bids
and I think it might be worth doing a bit of consolidation. I wanted to make this issue to discuss ways that we might do that, and offer a few initial suggestions. (I will also open a PR shortly after posting this issue implementing some of these suggestions to give a better idea of what this would look like in practice.)Additional detail
1. Testing files
First, I wanted to determine what the differentiation is between the files that are included in the
phys2bids/tests/data
directory versus the files that are on OSF and are downloaded in the test suite. Should we just move all the files in that directory onto OSF, or is there some reason they're included? For example, I can't find theTest_belt_pulse_multifreq.acq
orTest_multiscan100Hz_trig_samefreq_header.txt
that are in that directory used anywhere inphys2bids
, suggesting they should possibly be removed.I understand wanting to have some files for the documentation (e.g.,
tutorial_file.{txt,json}
), but I would be in favor of moving the remainder to OSF. If we're going to use a lot of files in documentation then we could consider making some user-facing "fetcher" functions (e.g.,fetch_tutorial_data()
). If it's all just for testing then we don't have to worry as much, though!2. Using
pytest.fixture
@vinferrer took the first steps in using
pytest.fixture
functionality to consolidate downloading the files intest_txt.py
, but I think we can use this to our advantage on a wider scale in the testing suite.pytest
allows aconftest.py
file in which you can put test-wide fixtures. I think we could move all the test downloads to that file and then they would be accessible to all thetest_X.py
modules. E.g.,Since the download steps are identical for each file I would recommend we make a small helper function, too:
Then we can have module-specific
pytest.fixture
functions that e.g., load these files (as @vinferrer did withtest_read_header_and_channels()
intest_txt.py
.(I would also suggest we download files to a temporary directory rather than to the
phys2bids/tests/data
directory, since that ends up cluttering the local git repo. We could usepytest
'stmp_path
functionality to do this.)3. Using
pytest.mark.parametrize
There are a lot of times where we're using the same file and just testing slightly different parameters (e.g., changing the units in the header of a file and checking that the output of some function changes in response). This is the perfect use case for
pytest.mark.parametrize
! Having looked attest_txt.py
most recently I know there are some functions where this could be used, but taking a quick peek at the test suite more broadly I think there are other places that would benefit from this, as well. E.g., looking attest_txt.test_process_acq()
, I think something like this could work:Next Steps
phys2bids/tests/data
directory to remove superfluous filespytest.fixture
decoratorspytest.mark.parametrize
more liberally throughout testing suiteSorry this got so long. Nonetheless, let me know your thoughts on all this! Looking forward to discussing with everyone ✨
The text was updated successfully, but these errors were encountered: