|
4 | 4 | retrieves it, and compares the (normalised) stored document against a saved |
5 | 5 | golden file (``full_features.expected.json``). |
6 | 6 |
|
7 | | -Requires live credentials in the environment (a ``.env`` file is loaded): |
| 7 | +This test creates and deletes a real draft, so it is opt-in: it only runs when |
| 8 | +``RUN_SUBSTACK_E2E`` is set **and** credentials are configured (a ``.env`` file |
| 9 | +is loaded). A normal ``pytest`` run with a ``.env`` present will skip it rather |
| 10 | +than touching the account. |
8 | 11 |
|
| 12 | + - ``RUN_SUBSTACK_E2E=1`` to enable |
9 | 13 | - ``COOKIES_STRING`` (or ``COOKIES_PATH``), **or** ``EMAIL`` + ``PASSWORD`` |
10 | 14 | - ``PUBLICATION_URL`` (optional but recommended) |
11 | 15 |
|
12 | | -The test is skipped when no credentials are configured, so it is safe to run in |
13 | | -CI without secrets. |
14 | | -
|
15 | 16 | To regenerate the golden file after an intentional change:: |
16 | 17 |
|
17 | 18 | python -m tests.substack.test_end_to_end --generate |
@@ -60,14 +61,23 @@ def walk(node): |
60 | 61 |
|
61 | 62 |
|
62 | 63 | def _has_credentials() -> bool: |
63 | | - """Whether auth is configured, checked without any network calls.""" |
64 | 64 | return bool( |
65 | 65 | os.getenv("COOKIES_STRING") |
66 | 66 | or os.getenv("COOKIES_PATH") |
67 | 67 | or (os.getenv("EMAIL") and os.getenv("PASSWORD")) |
68 | 68 | ) |
69 | 69 |
|
70 | 70 |
|
| 71 | +def _e2e_enabled() -> bool: |
| 72 | + """Only run when explicitly opted in AND credentials are present. |
| 73 | +
|
| 74 | + Creating/deleting real drafts should never happen by surprise on a local |
| 75 | + ``pytest`` run that merely has a ``.env`` file, so an explicit |
| 76 | + ``RUN_SUBSTACK_E2E`` opt-in is required. |
| 77 | + """ |
| 78 | + return bool(os.getenv("RUN_SUBSTACK_E2E")) and _has_credentials() |
| 79 | + |
| 80 | + |
71 | 81 | def _api_from_env() -> Api: |
72 | 82 | cookies_string = os.getenv("COOKIES_STRING") |
73 | 83 | cookies_path = os.getenv("COOKIES_PATH") |
@@ -141,7 +151,10 @@ def _roundtrip(api: Api): |
141 | 151 | pass |
142 | 152 |
|
143 | 153 |
|
144 | | -@pytest.mark.skipif(not _has_credentials(), reason="no Substack credentials configured") |
| 154 | +@pytest.mark.skipif( |
| 155 | + not _e2e_enabled(), |
| 156 | + reason="set RUN_SUBSTACK_E2E=1 and configure credentials to run the live e2e test", |
| 157 | +) |
145 | 158 | def test_full_features_roundtrip(): |
146 | 159 | api = _api_from_env() |
147 | 160 | content = _roundtrip(api) |
|
0 commit comments