tests.test_fakeapi.FakeAPI.shutdown()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
# tests/test_fakeapi.py
2
"""Module to test fake api usage.
3
4
Meant to serve as template in case the package uses non-local database.
5
"""
6
import pytest
7
8
9
class FakeAPI:
10
    """Fake API."""
11
12
    url = "http://localhost:5000/"
13
14
    @classmethod
15
    def create(cls):
16
        """Expensive operation to create API."""
17
        return FakeAPI()
18
19
    def shutdown(self):
20
        """Expensive shutdown operation."""
21
        return f"{self.url} performs expensive shutdown"
22
23
24
@pytest.fixture(scope="session")
25
def fake_api():
26
    """
27
    Yield api inerface when needed.
28
29
    Scope set to session, to only create once per test session.
30
31
    Yields
32
    ------
33
    FakeAPI
34
        FakeAPI instance using a localhost as url.
35
    """
36
    api = FakeAPI.create()
37
    yield api
38
    api.shutdown()
39