Skip to content

Commit 333a413

Browse files
committed
refactor: the fixture is a dataclass instead of a tuple
1 parent b20a27a commit 333a413

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ pytest-scim2-server creates a ``scim2_server`` fixture that runs an instance of
1616
import requests
1717

1818
def test_scim_foobar(scim2_server):
19-
host, port = scim2_server
20-
21-
res = request.get(f"http://{host}:{port}")
19+
res = request.get(f"http://localhost:{scim2_server.port}")
2220
...
2321
```
2422

@@ -32,8 +30,7 @@ from scim2_client.engines.httpx import SyncSCIMClient
3230

3331
@pytest.fixture(scope="session")
3432
def scim_client(scim2_server):
35-
host, port = scim2_server
36-
http_client = Client(base_url=f"http://{host}:{port}")
33+
http_client = Client(base_url=f"http://localhost:{scim2_server.port}")
3734
scim_client = SyncSCIMClient(http_client)
3835
scim_client.discover()
3936
return scim_client

pytest_scim2_server/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import threading
22
import wsgiref.simple_server
3+
from dataclasses import dataclass
34

45
import portpicker
56
import pytest
@@ -9,6 +10,17 @@
910
from scim2_server.utils import load_default_schemas
1011

1112

13+
@dataclass
14+
class Server:
15+
"""A proxy object that is returned by the pytest fixture."""
16+
17+
port: int
18+
"""The port on which the local http server listens."""
19+
20+
app: SCIMProvider
21+
"""The scim2-server WSGI application."""
22+
23+
1224
@pytest.fixture(scope="session")
1325
def scim2_server():
1426
"""SCIM2 server running in a thread."""
@@ -27,8 +39,11 @@ def scim2_server():
2739

2840
server_thread = threading.Thread(target=httpd.serve_forever)
2941
server_thread.start()
42+
43+
server = Server(port=port, app=provider)
44+
3045
try:
31-
yield host, port
46+
yield server
3247
finally:
3348
httpd.shutdown()
3449
server_thread.join()

tests/test_scim2_server.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
@pytest.fixture(scope="session")
77
def scim_client(scim2_server):
8-
host, port = scim2_server
9-
http_client = Client(base_url=f"http://{host}:{port}")
8+
http_client = Client(base_url=f"http://localhost:{scim2_server.port}")
109
scim_client = SyncSCIMClient(http_client)
1110
scim_client.discover()
1211
return scim_client

0 commit comments

Comments
 (0)