Skip to content

Commit

Permalink
Add test for missing requests module
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfeickert committed Sep 13, 2020
1 parent 3b78d18 commit 2317bab
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shlex
import pyhf
import time
import sys
import pytest


Expand Down Expand Up @@ -520,6 +521,35 @@ def test_patchset_download(datadir, script_runner, archive):
)


def test_missing_contrib_extra(datadir, script_runner):
module_name = "requests"

# hide
CACHE_MODULE, sys.modules[module_name] = sys.modules[module_name], None
assert sys.modules[module_name] is None

archive_url = "https://www.hepdata.net/record/resource/1408476?view=true"
command = (
f'pyhf contrib download {archive_url} {datadir.join("likelihoods").strpath}'
)
ret = script_runner.run(*shlex.split(command))
assert (
"import of requests halted; None in sys.modules"
+ "\nInstallation of the contrib extra is required for: pyhf contrib download"
+ "\nPlease install with: python -m pip install pyhf[contrib]"
in ret.stdout
)
assert (
"ModuleNotFoundError: import of requests halted; None in sys.modules"
in ret.stderr
)
assert not ret.success

# put back
CACHE_MODULE, sys.modules[module_name] = None, CACHE_MODULE
assert sys.modules[module_name] is not None


@pytest.mark.parametrize('output_file', [False, True])
@pytest.mark.parametrize('with_metadata', [False, True])
def test_patchset_extract(datadir, tmpdir, script_runner, output_file, with_metadata):
Expand Down

0 comments on commit 2317bab

Please sign in to comment.