Total Complexity | 3 |
Total Lines | 39 |
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 | """ |
||
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 |