|
6 | 6 | AsyncFetcher.adaptive = True |
7 | 7 |
|
8 | 8 |
|
| 9 | +@pytest.fixture |
| 10 | +def _reset_async_fetcher_config(): |
| 11 | + """Snapshot and restore the mutable class-level parser config around a test.""" |
| 12 | + snapshot = {k: getattr(AsyncFetcher, k) for k in AsyncFetcher.parser_keywords} |
| 13 | + try: |
| 14 | + yield |
| 15 | + finally: |
| 16 | + for k, v in snapshot.items(): |
| 17 | + setattr(AsyncFetcher, k, v) |
| 18 | + |
| 19 | + |
9 | 20 | @pytest_httpbin.use_class_based_httpbin |
10 | 21 | @pytest.mark.asyncio |
11 | 22 | class TestAsyncFetcher: |
@@ -124,3 +135,28 @@ async def test_delete_properties(self, fetcher, urls): |
124 | 135 | timeout=None, |
125 | 136 | ) |
126 | 137 | ).status == 200 |
| 138 | + |
| 139 | + async def test_configure_propagates_to_response( |
| 140 | + self, fetcher, urls, _reset_async_fetcher_config |
| 141 | + ): |
| 142 | + """`AsyncFetcher.configure()` must reach the Response's Selector on the HTTP path.""" |
| 143 | + AsyncFetcher.configure(adaptive=False, adaptive_domain="") |
| 144 | + baseline = await fetcher.get(urls["html_url"]) |
| 145 | + assert baseline._storage is None |
| 146 | + |
| 147 | + AsyncFetcher.configure(adaptive=True, adaptive_domain="configured.test") |
| 148 | + configured = await fetcher.get(urls["html_url"]) |
| 149 | + assert configured._storage is not None |
| 150 | + assert configured.url == "configured.test" |
| 151 | + |
| 152 | + async def test_selector_config_overrides_configure( |
| 153 | + self, fetcher, urls, _reset_async_fetcher_config |
| 154 | + ): |
| 155 | + """A per-request ``selector_config`` overrides the class-level configure().""" |
| 156 | + AsyncFetcher.configure(adaptive=True, adaptive_domain="from-configure.test") |
| 157 | + response = await fetcher.get( |
| 158 | + urls["html_url"], |
| 159 | + selector_config={"adaptive_domain": "from-request.test"}, |
| 160 | + ) |
| 161 | + assert response._storage is not None |
| 162 | + assert response.url == "from-request.test" |
0 commit comments