aboutsummaryrefslogtreecommitdiff
path: root/conftest.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-05-02 21:26:59 +0200
committerWojtek Kosior <koszko@koszko.org>2022-05-10 12:41:38 +0200
commit61f0aa75c64732063988826400ebc9f8e01ee3bb (patch)
tree3f1fadb196afe06892194eb31c731964c0f62f21 /conftest.py
parent9dda3aa988a9482d6292a655f4846f7d4b450315 (diff)
downloadhydrilla-builder-61f0aa75c64732063988826400ebc9f8e01ee3bb.tar.gz
hydrilla-builder-61f0aa75c64732063988826400ebc9f8e01ee3bb.zip
support piggybacking on APT packages
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)