|
1 | 1 | import inspect
|
| 2 | +import logging |
2 | 3 | import platform
|
3 | 4 | from contextlib import asynccontextmanager
|
| 5 | +from functools import wraps |
4 | 6 |
|
5 |
| -import pytest |
6 | 7 | from scrapy import Request
|
7 | 8 | from scrapy.http.response.html import HtmlResponse
|
8 | 9 | from scrapy.utils.test import get_crawler
|
9 | 10 |
|
10 | 11 |
|
| 12 | +logger = logging.getLogger("scrapy-playwright-tests") |
| 13 | + |
| 14 | + |
11 | 15 | if platform.system() == "Windows":
|
12 | 16 | from scrapy_playwright.handler import _WindowsAdapter
|
13 | 17 |
|
14 |
| - def windows_pytest_mark_asyncio(pytest_mark_asyncio): |
15 |
| - def wrapper(*args, **kwargs): |
16 |
| - if args and inspect.iscoroutinefunction(args[0]): |
| 18 | + def allow_windows(test_method): |
| 19 | + if not inspect.iscoroutinefunction(test_method): |
| 20 | + raise RuntimeError(f"{test_method} must be an async def method") |
17 | 21 |
|
18 |
| - async def method_proxy(*x): |
19 |
| - await _WindowsAdapter.get_result(args[0](*x)) |
| 22 | + @wraps(test_method) |
| 23 | + async def wrapped(self, *args, **kwargs): |
| 24 | + logger.debug("Calling _WindowsAdapter.get_result for %r", self) |
| 25 | + await _WindowsAdapter.get_result(test_method(self, *args, **kwargs)) |
20 | 26 |
|
21 |
| - return pytest_mark_asyncio(method_proxy) |
22 |
| - return windows_pytest_mark_asyncio(pytest_mark_asyncio(*args, **kwargs)) |
| 27 | + return wrapped |
23 | 28 |
|
24 |
| - return wrapper |
| 29 | +else: |
25 | 30 |
|
26 |
| - pytest.mark.asyncio = windows_pytest_mark_asyncio(pytest.mark.asyncio) |
| 31 | + def allow_windows(test_method): |
| 32 | + return test_method |
27 | 33 |
|
28 | 34 |
|
29 | 35 | @asynccontextmanager
|
|
0 commit comments