11import pyhf
22import pytest
33import json
4- import jsonschema
5- from functools import partial
64import importlib
75import sys
6+ from pytest_socket import socket_disabled # noqa: F401
87
98
109@pytest .mark .parametrize ('version' , ['1.0.0' ])
@@ -593,51 +592,6 @@ def test_patchset_fail(datadir, patchset_file):
593592 pyhf .schema .validate (patchset , 'patchset.json' )
594593
595594
596- def make_asserting_handler (origin ):
597- def asserting_handler (* args , ** kwargs ):
598- raise AssertionError (
599- f'called URL request handler from { origin } with args={ args !r} , kwargs={ kwargs !r} '
600- 'when no call should have been needed'
601- )
602-
603- return asserting_handler
604-
605-
606- @pytest .fixture
607- def no_http_jsonschema_ref_resolving (monkeypatch ):
608- asserting_handler = make_asserting_handler ('handlers' )
609- handlers = {
610- 'https' : asserting_handler ,
611- 'http' : asserting_handler ,
612- }
613- WrappedResolver = partial (jsonschema .RefResolver , handlers = handlers )
614- monkeypatch .setattr ('jsonschema.RefResolver' , WrappedResolver , raising = True )
615-
616-
617- @pytest .fixture
618- def no_requests (monkeypatch ):
619- monkeypatch .delattr ('requests.sessions.Session.request' , raising = True )
620- monkeypatch .setattr (
621- 'requests.get' , make_asserting_handler ('requests.get' ), raising = True
622- )
623-
624-
625- @pytest .fixture
626- def no_urllib (monkeypatch ):
627- monkeypatch .setattr (
628- 'urllib.request.urlopen' ,
629- make_asserting_handler ('urllib.request.urlopen' ),
630- raising = True ,
631- )
632-
633-
634- @pytest .fixture
635- def no_sockets (monkeypatch ):
636- monkeypatch .setattr (
637- 'socket.socket' , make_asserting_handler ('socket.socket' ), raising = True
638- )
639-
640-
641595@pytest .fixture
642596def refresh_pyhf (monkeypatch ):
643597 global pyhf
@@ -649,10 +603,7 @@ def refresh_pyhf(monkeypatch):
649603
650604
651605def test_defs_always_cached (
652- no_http_jsonschema_ref_resolving , # this should catch the request and raise the error if it happens
653- no_requests , # future jsonschema code may try to fall back to to explicit/default handlers
654- no_urllib ,
655- no_sockets ,
606+ socket_disabled , # noqa: F811
656607 refresh_pyhf , # ensure there is not a pre-existing cache hiding the issue
657608):
658609 """
0 commit comments