|
1 | 1 | """Unit tests for private helpers in tests/conftest.py.""" |
2 | 2 |
|
3 | | -import pytest |
4 | | - |
5 | 3 | from tests.conftest import _build_worker_url, _worker_schema_name |
6 | 4 |
|
7 | 5 |
|
8 | 6 | class TestWorkerSchemaName: |
9 | 7 | def test_valid_gw0(self): |
| 8 | + """Return a schema name for the first xdist worker.""" |
10 | 9 | assert _worker_schema_name("gw0") == "test_worker_0" |
11 | 10 |
|
12 | 11 | def test_valid_gw99(self): |
| 12 | + """Return a schema name for multi-digit xdist workers.""" |
13 | 13 | assert _worker_schema_name("gw99") == "test_worker_99" |
14 | 14 |
|
15 | 15 | def test_master_returns_none(self): |
| 16 | + """Return ``None`` when pytest is not running under xdist.""" |
16 | 17 | assert _worker_schema_name("master") is None |
17 | 18 |
|
18 | 19 | def test_non_gw_id_returns_none(self): |
| 20 | + """Ignore worker IDs that do not match the xdist pattern.""" |
19 | 21 | assert _worker_schema_name("worker1") is None |
20 | 22 |
|
21 | 23 | def test_partial_match_returns_none(self): |
| 24 | + """Require a full worker ID match before creating a schema name.""" |
22 | 25 | # "gw0extra" should not match the fullmatch pattern |
23 | 26 | assert _worker_schema_name("gw0extra") is None |
24 | 27 |
|
25 | 28 |
|
26 | 29 | class TestBuildWorkerUrl: |
27 | 30 | def test_url_without_options(self): |
| 31 | + """Add a search path option when the URL has no existing options.""" |
28 | 32 | url = "postgresql://user:pass@localhost/testdb" |
29 | 33 | result = _build_worker_url(url, "test_worker_0") |
30 | 34 | assert "options" in result |
31 | 35 | assert "search_path%3Dtest_worker_0" in result or "search_path=test_worker_0" in result |
32 | 36 |
|
33 | 37 | def test_url_with_existing_options_appends(self): |
| 38 | + """Append the worker search path to existing connection options.""" |
34 | 39 | url = "postgresql://user:pass@localhost/testdb?options=-cstatement_timeout%3D5000" |
35 | 40 | result = _build_worker_url(url, "test_worker_1") |
36 | 41 | # The new search_path must be present |
|
0 commit comments