bids-standard / pybv

A lightweight I/O utility for the BrainVision data format, written in Python.

Home Page:https://pybv.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

switch "manual" tempdirs for testing to pytest tmpdir fixtures

sappelhoff opened this issue · comments

Making use of this feature: https://docs.pytest.org/en/stable/tmpdir.html

Replacing this code:

@pytest.mark.parametrize("meas_date,match",
[(1, '`meas_date` must be of type str, datetime'),
('', 'Got a str for `meas_date`, but it was'),
('1973', 'Got a str for `meas_date`, but it was')])
def test_bad_meas_date(meas_date, match):
"""Test that bad measurement dates raise errors."""
tmpdir = _mktmpdir()
with pytest.raises(ValueError, match=match):
write_brainvision(data, sfreq, ch_names, fname, tmpdir,
meas_date=meas_date)
rmtree(tmpdir)

... with the following:

 @pytest.mark.parametrize("meas_date,match", 
                          [(1, '`meas_date` must be of type str, datetime'), 
                           ('', 'Got a str for `meas_date`, but it was'), 
                           ('1973', 'Got a str for `meas_date`, but it was')]) 
+ def test_bad_meas_date(tmpdir, meas_date, match): 
     """Test that bad measurement dates raise errors.""" 
-     tmpdir = _mktmpdir() 
     with pytest.raises(ValueError, match=match): 
         write_brainvision(data, sfreq, ch_names, fname, tmpdir, 
                           meas_date=meas_date) 
-     rmtree(tmpdir) 

This would clean up the code by a bit and follow best practice for pytest.