Skip to content

Commit

Permalink
fix: Use function scope to avoid altering hypotest_args fixture (#2011)
Browse files Browse the repository at this point in the history
* Use the 'function' scope for hypotest_args fixture. Fixing the POI in the model config
  changes it for the entire fixture if the fixture is 'module' scope, which would cause
  errors in other tests that later use it and defeats the point of the fixture.
* Remove unnecessary use of tmpdir fixture as no output is written.
  • Loading branch information
matthewfeickert committed Sep 20, 2022
1 parent 2a326f7 commit f7e974f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tests/test_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import scipy.stats


@pytest.fixture(scope='module')
@pytest.fixture(scope="function")
def hypotest_args():
pdf = pyhf.simplemodels.uncorrelated_background(
signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
Expand Down Expand Up @@ -466,16 +466,16 @@ def test_toy_calculator(tmpdir, hypotest_args):
)


def test_fixed_poi(tmpdir, hypotest_args):
def test_fixed_poi(hypotest_args):
"""
Check that the return structure of pyhf.infer.hypotest with the
addition of the return_expected keyword arg is as expected
"""

_, _, pdf = hypotest_args
pdf.config.param_set('mu').suggested_fixed = [True]
test_poi, data, model = hypotest_args
model.config.param_set("mu").suggested_fixed = [True]
with pytest.raises(pyhf.exceptions.InvalidModel):
pyhf.infer.hypotest(*hypotest_args)
pyhf.infer.hypotest(test_poi, data, model)


def test_teststat_nan_guard():
Expand Down

0 comments on commit f7e974f

Please sign in to comment.