Total Complexity | 3 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 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 | """Yield api inerface when needed. |
||
27 | |||
28 | Scope set to session, to only create once per test session. |
||
29 | |||
30 | Yields |
||
31 | ------ |
||
32 | FakeAPI |
||
33 | FakeAPI instance using a localhost as url. |
||
34 | """ |
||
35 | api = FakeAPI.create() |
||
36 | yield api |
||
37 | api.shutdown() |
||
38 |