aboutsummaryrefslogtreecommitdiff
path: root/conftest.py
diff options
context:
space:
mode:
Diffstat (limited to 'conftest.py')
-rw-r--r--conftest.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/conftest.py b/conftest.py
index 1aef80a..141cba5 100644
--- a/conftest.py
+++ b/conftest.py
@@ -7,5 +7,30 @@
import sys
from pathlib import Path
+import pytest
+
here = Path(__file__).resolve().parent
sys.path.insert(0, str(here / 'src'))
+
+@pytest.fixture(autouse=True)
+def no_requests(monkeypatch):
+ """Remove requests.sessions.Session.request for all tests."""
+ monkeypatch.delattr('requests.sessions.Session.request')
+
+@pytest.fixture
+def mock_subprocess_run(monkeypatch, request):
+ """
+ Temporarily replace subprocess.run() with a function supplied through pytest
+ marker 'subprocess_run'.
+
+ The marker excepts 2 arguments:
+ * the module inside which the subprocess attribute should be mocked and
+ * a run() function to use.
+ """
+ where, mocked_run = request.node.get_closest_marker('subprocess_run').args
+
+ class MockedSubprocess:
+ """Minimal mocked version of the subprocess module."""
+ run = mocked_run
+
+ monkeypatch.setattr(where, 'subprocess', MockedSubprocess)