tests.test_fakeapi   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A FakeAPI.shutdown() 0 3 1
A FakeAPI.create() 0 4 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A fake_api() 0 15 1
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