Skip to content

Commit

Permalink
Avoid
Browse files Browse the repository at this point in the history
deprecated in pytest 8 warning
  • Loading branch information
matthewfeickert committed Feb 10, 2022
1 parent 760f27f commit 989bb55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Expand Up @@ -82,6 +82,9 @@ filterwarnings = [
'ignore:distutils Version classes are deprecated:DeprecationWarning', # tensorflow-probability
'ignore:the `interpolation=` argument to percentile was renamed to `method=`, which has additional options:DeprecationWarning', # Issue #1772
"ignore:The interpolation= argument to 'quantile' is deprecated. Use 'method=' instead:DeprecationWarning", # Issue #1772
'ignore: Exception ignored in:pytest.PytestUnraisableExceptionWarning', #FIXME: Exception ignored in: <_io.FileIO [closed]>
'ignore:invalid value encountered in true_divide:RuntimeWarning', #FIXME
'ignore:invalid value encountered in add:RuntimeWarning', #FIXME
"ignore:In future, it will be an error for 'np.bool_' scalars to be interpreted as an index:DeprecationWarning", #FIXME: tests/test_tensor.py::test_pdf_eval[pytorch]
'ignore:Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with:UserWarning', #FIXME: tests/test_optim.py::test_minimize[no_grad-scipy-pytorch-no_stitch]
'ignore:divide by zero encountered in true_divide:RuntimeWarning', #FIXME: pytest tests/test_tensor.py::test_pdf_calculations[numpy]
Expand Down
19 changes: 8 additions & 11 deletions tests/test_export.py
Expand Up @@ -352,17 +352,14 @@ def test_export_sample_zerodata(mocker, spec):
sampledata = [0.0] * len(samplespec['data'])

mocker.patch('pyhf.writexml._ROOT_DATA_FILE')
# make sure no RuntimeWarning, https://stackoverflow.com/a/45671804
with pytest.warns(None) as record:

This comment has been minimized.

Copy link
@henryiii

henryiii Feb 10, 2022

Member

Remembering the changelog in PyTest 7:

#8645: pytest.warns(None) is now deprecated because many people used it to mean “this code does not emit warnings”, but it actually had the effect of checking that the code emits at least one warning of any type - like pytest.warns() or pytest.warns(Warning).

So was this producing a warning?

This comment has been minimized.

Copy link
@matthewfeickert

matthewfeickert Feb 10, 2022

Author Member

The

with pytest.warns(None) as record

was causing a

pytest.PytestRemovedIn8Warning: Passing None has been deprecated.

So the block inside wasn't, but the context manager was. I removed it all as it was just checking that there was no RuntimeWarning in a hacky way, and now this PR does that anyway everywhere.

for modifierspec in samplespec['modifiers']:
pyhf.writexml.build_modifier(
{'measurements': [{'config': {'parameters': []}}]},
modifierspec,
channelname,
samplename,
sampledata,
)
assert not record.list
for modifierspec in samplespec['modifiers']:
pyhf.writexml.build_modifier(
{'measurements': [{'config': {'parameters': []}}]},
modifierspec,
channelname,
samplename,
sampledata,
)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 989bb55

Please sign in to comment.