Project

General

Profile

Download (1.05 KB) Statistics
| Branch: | Tag: | Revision:

hydrilla-builder / conftest.py @ 61f0aa75

1
# SPDX-License-Identifier: CC0-1.0
2

    
3
# Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
4
#
5
# Available under the terms of Creative Commons Zero v1.0 Universal.
6

    
7
import sys
8
from pathlib import Path
9

    
10
import pytest
11

    
12
here = Path(__file__).resolve().parent
13
sys.path.insert(0, str(here / 'src'))
14

    
15
@pytest.fixture(autouse=True)
16
def no_requests(monkeypatch):
17
    """Remove requests.sessions.Session.request for all tests."""
18
    monkeypatch.delattr('requests.sessions.Session.request')
19

    
20
@pytest.fixture
21
def mock_subprocess_run(monkeypatch, request):
22
    """
23
    Temporarily replace subprocess.run() with a function supplied through pytest
24
    marker 'subprocess_run'.
25

    
26
    The marker excepts 2 arguments:
27
    * the module inside which the subprocess attribute should be mocked and
28
    * a run() function to use.
29
    """
30
    where, mocked_run = request.node.get_closest_marker('subprocess_run').args
31

    
32
    class MockedSubprocess:
33
        """Minimal mocked version of the subprocess module."""
34
        run = mocked_run
35

    
36
    monkeypatch.setattr(where, 'subprocess', MockedSubprocess)
(6-6/9)