aboutsummaryrefslogtreecommitdiff
path: root/tests/playwright/conftest.py
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-12-14 19:13:38 +0100
committerDaniel Schadt <kingdread@gmx.de>2022-12-14 19:13:38 +0100
commit2216398346b49a13ec217a924c583b05de47e889 (patch)
treeff6297face309dd5d7db791e60e84e0cb6c34ed7 /tests/playwright/conftest.py
parent22566209bee83c1ba78f28b57d8aa802fe33d505 (diff)
parent58d1da5606d3bfe241e18fdf9416ec9a28f3a3f1 (diff)
downloadfietsboek-2216398346b49a13ec217a924c583b05de47e889.tar.gz
fietsboek-2216398346b49a13ec217a924c583b05de47e889.tar.bz2
fietsboek-2216398346b49a13ec217a924c583b05de47e889.zip
Merge branch 'playwright'
Diffstat (limited to 'tests/playwright/conftest.py')
-rw-r--r--tests/playwright/conftest.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/playwright/conftest.py b/tests/playwright/conftest.py
new file mode 100644
index 0000000..dedaf22
--- /dev/null
+++ b/tests/playwright/conftest.py
@@ -0,0 +1,48 @@
+import socket
+import threading
+from wsgiref import simple_server
+
+import pytest
+
+
+@pytest.fixture(scope="session")
+def server_port():
+ """Return a (likely) free port.
+
+ Note that due to OS race conditions between picking the port and opening
+ something on it, it might be taken again, but that is unlikely.
+ """
+ sock = socket.socket(socket.AF_INET)
+ sock.bind(("", 0))
+ port = sock.getsockname()[1]
+ sock.close()
+ return port
+
+
+@pytest.fixture(scope="session", autouse=True)
+def running_server(server_port, app):
+ """Have the app running as an actual server."""
+ server = simple_server.make_server("127.0.0.1", server_port, app)
+ thread = threading.Thread(target=server.serve_forever)
+ thread.daemon = True
+ thread.start()
+ yield
+ server.shutdown()
+
+
+@pytest.fixture
+def browser_context_args(server_port) -> dict:
+ return {"base_url": f"http://localhost:{server_port}"}
+
+
+@pytest.fixture
+def dbaccess(app):
+ """Provide direct access to the database.
+
+ This is needed for the selenium tests, because the normal "dbsession"
+ fixture has a doomed transaction attached. This is nice for keeping the
+ test database clean, but it does mean that the changes are not propagated
+ through and the running WSGI app cannot read them.
+ """
+ session_factory = app.registry["dbsession_factory"]
+ return session_factory()