Skip to content

Commit

Permalink
replaced _jail with function_jail
Browse files Browse the repository at this point in the history
  • Loading branch information
emolter committed Mar 6, 2024
1 parent 64d050b commit 9fcff43
Show file tree
Hide file tree
Showing 31 changed files with 76 additions and 57 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ general
- Replaced all instances of pytest ``tmpdir`` and ``tmpdir_factory``
fixtures with ``tmp_path`` and ``tmp_path_factory``. [#8327]

- Replaced the ``_jail`` fixture from ``ci_watson`` with a local copy
of the fixture named ``function_jail`` to enforce ``no:legacypath``
in the CI tests. [#8327]

jump
----

Expand Down
2 changes: 1 addition & 1 deletion jwst/associations/lib/tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def test_fails(mismatched, standard=standard_asn):
asn_diff.compare_asn_lists(left_asns, right_asns)


@pytest.mark.usefixtures('_jail')
@pytest.mark.usefixtures('function_jail')
def test_fromfiles():
"""Test from files
Expand Down
2 changes: 1 addition & 1 deletion jwst/associations/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_asn_candidates(pool, all_candidates, case):
(['nosuchpool.csv'], 1),
]
)
def test_cmdline_status(args, expected, _jail):
def test_cmdline_status(args, expected, function_jail):
"""Ensure command line status are as expected."""
full_args = ['asn_generate'] + args
status = subprocess.run(full_args)
Expand Down
6 changes: 3 additions & 3 deletions jwst/background/tests/test_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def science_image():
return image


def test_nirspec_gwa(_jail, background, science_image):
def test_nirspec_gwa(function_jail, background, science_image):
"""Verify NIRSPEC GWA logic for in the science and background"""

# open the background to read in the GWA values
Expand All @@ -106,7 +106,7 @@ def test_nirspec_gwa(_jail, background, science_image):
back_image.close()


def test_nirspec_gwa_xtilt(_jail, background, science_image):
def test_nirspec_gwa_xtilt(function_jail, background, science_image):
"""Verify NIRSPEC GWA Xtilt must be the same in the science and background image"""

# open the background to read in the GWA values
Expand All @@ -128,7 +128,7 @@ def test_nirspec_gwa_xtilt(_jail, background, science_image):
back_image.close()


def test_nirspec_gwa_ytilt(_jail, background, science_image):
def test_nirspec_gwa_ytilt(function_jail, background, science_image):
"""Verify NIRSPEC GWA Ytilt must be the same in the science and background image"""

# open the background to read in the GWA values
Expand Down
15 changes: 15 additions & 0 deletions jwst/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ def jail(request, tmp_path_factory):
os.chdir(old_dir)


@pytest.fixture(scope="function")
def function_jail(request, tmp_path_factory):
"""
Run test in a pristine temporary working directory, scoped to function.
"""
old_dir = os.getcwd()
path = request.module.__name__.split('.')[-1]
if request._parent_request.fixturename is not None:
path = path + "_" + request._parent_request.fixturename
newpath = tmp_path_factory.mktemp(path)
os.chdir(str(newpath))
yield newpath
os.chdir(old_dir)


@pytest.hookimpl(trylast=True)
def pytest_configure(config):
terminal_reporter = config.pluginmanager.getplugin('terminalreporter')
Expand Down
10 changes: 5 additions & 5 deletions jwst/cube_build/tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def nirspec_medium_coverage():
return input_models


def test_calspec2_config(_jail, miri_ifushort_short):
def test_calspec2_config(function_jail, miri_ifushort_short):
""" Determine cube based on calspec2 setup """

pars_input = {}
Expand Down Expand Up @@ -249,7 +249,7 @@ def test_calspec2_config(_jail, miri_ifushort_short):
assert cube_pars['1']['par2'] == ['short', 'short']


def test_calspec3_config_miri(_jail, miri_full_coverage):
def test_calspec3_config_miri(function_jail, miri_full_coverage):
""" Test CalSpec3 MIRI configuration default band cubes"""

pars_input = {}
Expand Down Expand Up @@ -322,7 +322,7 @@ def test_calspec3_config_miri(_jail, miri_full_coverage):
assert cube_pars['12']['par2'] == ['long']


def test_calspec3_config_miri_multi(_jail, miri_full_coverage):
def test_calspec3_config_miri_multi(function_jail, miri_full_coverage):
""" Test CalSpec3 MIRI configuration default band cubes"""

pars_input = {}
Expand Down Expand Up @@ -376,7 +376,7 @@ def test_calspec3_config_miri_multi(_jail, miri_full_coverage):
'short', 'medium', 'long']


def test_calspec3_config_nirspec(_jail, nirspec_medium_coverage):
def test_calspec3_config_nirspec(function_jail, nirspec_medium_coverage):
""" Test CalSpec3 configuration for NIRSpec - default band cubes"""

pars_input = {}
Expand Down Expand Up @@ -424,7 +424,7 @@ def test_calspec3_config_nirspec(_jail, nirspec_medium_coverage):
assert cube_pars['2']['par2'] == ['f170lp']


def test_calspec3_config_nirspec_multi(_jail, nirspec_medium_coverage):
def test_calspec3_config_nirspec_multi(function_jail, nirspec_medium_coverage):
""" Test CalSpec3 configuration for NIRSpec - Multiband cubes"""

pars_input = {}
Expand Down
4 changes: 2 additions & 2 deletions jwst/cube_build/tests/test_cube_build_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def miri_image():


@pytest.mark.parametrize("as_filename", [True, False])
def test_call_cube_build(_jail, miri_cube_pars, miri_image, tmp_path, as_filename):
def test_call_cube_build(function_jail, miri_cube_pars, miri_image, tmp_path, as_filename):
""" test defaults of step are set up and user input are defined correctly """
if as_filename:
fn = tmp_path / 'miri.fits'
Expand Down Expand Up @@ -181,7 +181,7 @@ def nirspec_data():


@pytest.mark.parametrize("as_filename", [True, False])
def test_call_cube_build_nirspec(_jail, nirspec_data, tmp_path, as_filename):
def test_call_cube_build_nirspec(function_jail, nirspec_data, tmp_path, as_filename):
if as_filename:
fn = tmp_path / 'test_nirspec.fits'
nirspec_data.save(fn)
Expand Down
6 changes: 3 additions & 3 deletions jwst/cube_build/tests/test_miri_cubepars.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def miri_cube_pars(tmp_path_factory):
return filename


def test_miri_use_cubepars(_jail, miri_cube_pars):
def test_miri_use_cubepars(function_jail, miri_cube_pars):
""" Test reading in the miri cube pars file """

instrument_info = instrument_defaults.InstrumentInfo()
Expand Down Expand Up @@ -183,7 +183,7 @@ def test_miri_use_cubepars(_jail, miri_cube_pars):
assert math.isclose(this_cube.spatial_size, 0.13, abs_tol=0.00001)


def test_miri_cubepars_user_defaults(_jail, miri_cube_pars):
def test_miri_cubepars_user_defaults(function_jail, miri_cube_pars):
""" Read in the miri cube pars file and override some defaults """

instrument_info = instrument_defaults.InstrumentInfo()
Expand Down Expand Up @@ -326,7 +326,7 @@ def test_miri_cubepars_user_defaults(_jail, miri_cube_pars):
assert math.isclose(this_cube.rois, user_rois, abs_tol=0.00001)


def test_miri_cubepars_multiple_bands(_jail, miri_cube_pars):
def test_miri_cubepars_multiple_bands(function_jail, miri_cube_pars):
"""Read in the miri cube pars file. Test cube has correct values when
multiple bands are used
"""
Expand Down
2 changes: 1 addition & 1 deletion jwst/cube_build/tests/test_nirspec_cubepars.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def nirspec_cube_pars(tmp_path_factory):
return filename


def test_nirspec_cubepars(_jail, nirspec_cube_pars):
def test_nirspec_cubepars(function_jail, nirspec_cube_pars):
""" Read in the nirspec cube pars file """

instrument_info = instrument_defaults.InstrumentInfo()
Expand Down
2 changes: 1 addition & 1 deletion jwst/exp_to_source/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_default_run(tmp_path, capsys):
assert len(files) == 5


def test_dry_run(_jail, capsys):
def test_dry_run(function_jail, capsys):
no_files = glob('*.fits')
assert len(no_files) == 0

Expand Down
2 changes: 1 addition & 1 deletion jwst/extract_1d/tests/test_apply_apcorr_ifu.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_select_apcorr_nirspec(nirspec_cube):
assert apcorr_cls == ApCorrRadial


def test_table_type_miri(_jail, dummy_miri_ref, miri_cube):
def test_table_type_miri(function_jail, dummy_miri_ref, miri_cube):
dummy_wave = np.zeros(100) + 0.5
with MirMrsApcorrModel(dummy_miri_ref) as apcorr_model:
table = apcorr_model.apcorr_table
Expand Down
4 changes: 2 additions & 2 deletions jwst/master_background/tests/test_master_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def science_image():
return image


def test_master_background_userbg(_jail, user_background, science_image):
def test_master_background_userbg(function_jail, user_background, science_image):
"""Verify data can run through the step with a user-supplied background"""

# Run with a user-supplied background and verify this is recorded in header
Expand All @@ -68,7 +68,7 @@ def test_master_background_userbg(_jail, user_background, science_image):
assert result.meta.background.master_background_file == 'user_background.fits'


def test_master_background_logic(_jail, user_background, science_image):
def test_master_background_logic(function_jail, user_background, science_image):
"""Verify if calspec 2 background step was run the master background step will be skipped"""

# the background step in calspec2 was done
Expand Down
2 changes: 1 addition & 1 deletion jwst/mrs_imatch/tests/test_apply_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def miri_dither_ch12():
return input_models


def test_apply_background_2d(_jail, miri_dither_ch12):
def test_apply_background_2d(function_jail, miri_dither_ch12):
""" Test if background polynomial is set it is subtracted correctly"""

all_models = ModelContainer(miri_dither_ch12)
Expand Down
6 changes: 3 additions & 3 deletions jwst/mrs_imatch/tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def miri_dither_ch12():
return input_models


def test_imatch_background_subtracted(_jail, miri_dither_ch12):
def test_imatch_background_subtracted(function_jail, miri_dither_ch12):
""" Test if data is already background subtracted - raise error"""

all_models = ModelContainer(miri_dither_ch12)
Expand All @@ -73,7 +73,7 @@ def test_imatch_background_subtracted(_jail, miri_dither_ch12):
step.run(new_container)


def test_imatch_background_reset(_jail, miri_dither_ch12):
def test_imatch_background_reset(function_jail, miri_dither_ch12):
""" Test if background polynomial is already determined - reset it"""

all_models = ModelContainer(miri_dither_ch12)
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_imatch_background_reset(_jail, miri_dither_ch12):
assert test == 0


def test_find_channel_index(_jail, miri_dither_ch12):
def test_find_channel_index(function_jail, miri_dither_ch12):
""" Test if correct channel index is returned """

# channel 1 - model only has 1 background polynomial
Expand Down
12 changes: 6 additions & 6 deletions jwst/outlier_detection/tests/test_outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def we_three_sci():
return we_many_sci(numsci=3)


def test_outlier_step_no_outliers(we_three_sci, _jail):
def test_outlier_step_no_outliers(we_three_sci, function_jail):
"""Test whole step, no outliers"""
container = ModelContainer(list(we_three_sci))
pristine = container.copy()
Expand All @@ -177,7 +177,7 @@ def test_outlier_step_no_outliers(we_three_sci, _jail):
np.testing.assert_allclose(image.dq, corrected.dq)


def test_outlier_step(we_three_sci, _jail):
def test_outlier_step(we_three_sci, function_jail):
"""Test whole step with an outlier including saving intermediate and results files"""
container = ModelContainer(list(we_three_sci))

Expand All @@ -200,7 +200,7 @@ def test_outlier_step(we_three_sci, _jail):
assert result[0].dq[12, 12] == OUTLIER_DO_NOT_USE


def test_outlier_step_on_disk(we_three_sci, _jail):
def test_outlier_step_on_disk(we_three_sci, function_jail):
"""Test whole step with an outlier including saving intermediate and results files"""

for model in we_three_sci:
Expand Down Expand Up @@ -230,7 +230,7 @@ def test_outlier_step_on_disk(we_three_sci, _jail):
assert result[0].dq[12, 12] == OUTLIER_DO_NOT_USE


def test_outlier_step_square_source_no_outliers(we_three_sci, _jail):
def test_outlier_step_square_source_no_outliers(we_three_sci, function_jail):
"""Test whole step with square source with sharp edges, no outliers"""
container = ModelContainer(list(we_three_sci))

Expand All @@ -256,7 +256,7 @@ def test_outlier_step_square_source_no_outliers(we_three_sci, _jail):


@pytest.mark.parametrize("exptype", IMAGE_MODES)
def test_outlier_step_image_weak_CR_dither(exptype, _jail):
def test_outlier_step_image_weak_CR_dither(exptype, function_jail):
"""Test whole step with an outlier for imaging modes"""
bkg = 1.5
sig = 0.02
Expand All @@ -283,7 +283,7 @@ def test_outlier_step_image_weak_CR_dither(exptype, _jail):


@pytest.mark.parametrize("exptype, tsovisit", exptypes_tso + exptypes_coron)
def test_outlier_step_image_weak_CR_nodither(exptype, tsovisit, _jail):
def test_outlier_step_image_weak_CR_nodither(exptype, tsovisit, function_jail):
"""Test whole step with an outlier for TSO & coronagraphic modes"""
bkg = 1.5
sig = 0.02
Expand Down
4 changes: 2 additions & 2 deletions jwst/regtest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def artifactory_result_path():
postmortem(request, 'sdpdata_module')
if rtdata:
try:
# The _jail fixture from ci_watson sets tmp_path
# The function_jail fixture sets tmp_path
cwd = str(request.node.funcargs['tmp_path'])
except KeyError:
# The jail fixture (module-scoped) returns the path
Expand Down Expand Up @@ -210,7 +210,7 @@ def _rtdata_fixture_implementation(artifactory_repos, envopt, request):


@pytest.fixture(scope='function')
def rtdata(artifactory_repos, envopt, request, _jail):
def rtdata(artifactory_repos, envopt, request, function_jail):
return _rtdata_fixture_implementation(artifactory_repos, envopt, request)


Expand Down
4 changes: 2 additions & 2 deletions jwst/regtest/test_miri_dark.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'exposure',
['jw00001001001_01101_00001_mirimage', 'jw02201001001_01101_00001_MIRIMAGE']
)
def test_miri_dark_pipeline(exposure, _jail, rtdata, fitsdiff_default_kwargs):
def test_miri_dark_pipeline(exposure, function_jail, rtdata, fitsdiff_default_kwargs):
"""Test the DarkPipeline on MIRI dark exposures"""
rtdata.get_data(f"miri/image/{exposure}_uncal.fits")

Expand All @@ -28,7 +28,7 @@ def test_miri_dark_pipeline(exposure, _jail, rtdata, fitsdiff_default_kwargs):
'exposure',
['jw01033005001_04103_00001-seg003_mirimage']
)
def test_miri_segmented_dark(exposure, _jail, rtdata, fitsdiff_default_kwargs):
def test_miri_segmented_dark(exposure, function_jail, rtdata, fitsdiff_default_kwargs):
"""Test the dark_current step on MIRI segmented exposures"""
rtdata.get_data(f"miri/image/{exposure}_linearity.fits")

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_setpointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@pytest.mark.bigdata
def test_miri_setpointing(_jail, rtdata, engdb, fitsdiff_default_kwargs):
def test_miri_setpointing(function_jail, rtdata, engdb, fitsdiff_default_kwargs):
"""
Regression test of the set_telescope_pointing script on a level-1b MIRI image.
"""
Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_spectral_leak.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'output',
['test_spectral_leak_asn_0_spectralleakstep.fits', 'test_spectral_leak_asn_1_spectralleakstep.fits']
)
def test_miri_spectral_leak(output, _jail, rtdata, fitsdiff_default_kwargs):
def test_miri_spectral_leak(output, function_jail, rtdata, fitsdiff_default_kwargs):
"""Run cube_build on single file using coord system = ifu_align"""

rtdata.get_asn("miri/mrs/test_spectral_leak_asn.json")
Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_nircam_tsgrism.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_nircam_tsgrism_stage3_whtlt(run_pipelines):


@pytest.mark.bigdata
def test_nircam_setpointing_tsgrism(_jail, rtdata, fitsdiff_default_kwargs):
def test_nircam_setpointing_tsgrism(function_jail, rtdata, fitsdiff_default_kwargs):
"""
Regression test of the set_telescope_pointing script on a level-1b NIRCam file.
"""
Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_nircam_tsimg.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_nircam_tsimage_stage3_phot(run_pipelines):


@pytest.mark.bigdata
def test_nircam_setpointing_tsimg(_jail, rtdata, engdb, fitsdiff_default_kwargs):
def test_nircam_setpointing_tsimg(function_jail, rtdata, engdb, fitsdiff_default_kwargs):
"""
Regression test of the set_telescope_pointing script on a level-1b
NIRCam TSO imaging file.
Expand Down
Loading

0 comments on commit 9fcff43

Please sign in to comment.