Skip to content

Commit

Permalink
Fix importorskip in test_hooks; add tmp_cwd fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavies-st committed Jan 17, 2024
1 parent fea26c0 commit 01881d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
from pathlib import Path

import pytest


@pytest.fixture()
def tmp_cwd(tmp_path):
"""Perform test in a pristine temporary working directory."""
old_dir = Path.cwd()
os.chdir(tmp_path)
try:
yield tmp_path
finally:
os.chdir(old_dir)
10 changes: 6 additions & 4 deletions tests/test_hooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest

Step = pytest.importorskip("jwst.stpipe.Step")
Pipeline = pytest.importorskip("jwst.stpipe.Pipeline")
pytest.importorskip("jwst")

from jwst.stpipe import Pipeline, Step # noqa: E402


class ShovelPixelsStep(Step):
Expand Down Expand Up @@ -35,6 +36,7 @@ def process(self, input_data):
return result



class HookStep(Step):
class_alias = "myhook"

Expand Down Expand Up @@ -131,12 +133,12 @@ def test_hook_as_string_of_importable_function(caplog):
assert "Running hook_function on data array of size (10, 10)" in caplog.text


def test_hook_as_subproccess(caplog, tmp_path):
def test_hook_as_subproccess(caplog, tmp_cwd):
"""Test a string of a terminal command"""
datamodels = pytest.importorskip("stdatamodels.jwst.datamodels")
model = datamodels.ImageModel((10, 10))
filename = "test_hook_as_subprocess.fits"
path = tmp_path / filename
path = tmp_cwd / filename
model.save(path)

# Run post_hooks of "fitsinfo" and "fitsheader" CLI scripts from astropy
Expand Down

0 comments on commit 01881d4

Please sign in to comment.