-
-
Notifications
You must be signed in to change notification settings - Fork 866
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TST Make
pyodide-test-runner
installable (#2742)
- Loading branch information
1 parent
bfd364b
commit 7d7b7e8
Showing
17 changed files
with
252 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# pyodide-test-runner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pytest_plugins = [ | ||
"pyodide_test_runner.hook", | ||
"pyodide_test_runner.fixture", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import ast | ||
import sys | ||
from copy import deepcopy | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
import pytest | ||
from _pytest.assertion.rewrite import AssertionRewritingHook, rewrite_asserts | ||
from _pytest.python import ( | ||
pytest_pycollect_makemodule as orig_pytest_pycollect_makemodule, | ||
) | ||
|
||
|
||
def pytest_configure(config): | ||
|
||
config.addinivalue_line( | ||
"markers", | ||
"skip_refcount_check: Don't run refcount checks", | ||
) | ||
|
||
config.addinivalue_line( | ||
"markers", | ||
"skip_pyproxy_check: Don't run pyproxy allocation checks", | ||
) | ||
|
||
config.addinivalue_line( | ||
"markers", | ||
"driver_timeout: Set script timeout in WebDriver", | ||
) | ||
|
||
config.addinivalue_line( | ||
"markers", | ||
"xfail_browsers: xfail a test in specific browsers", | ||
) | ||
|
||
pytest.pyodide_dist_dir = config.getoption("--dist-dir") | ||
|
||
|
||
@pytest.hookimpl(tryfirst=True) | ||
def pytest_addoption(parser): | ||
group = parser.getgroup("general") | ||
group.addoption( | ||
"--dist-dir", | ||
action="store", | ||
default="pyodide", | ||
help="Path to the pyodide dist directory", | ||
type=Path, | ||
) | ||
group.addoption( | ||
"--runner", | ||
default="selenium", | ||
choices=["selenium", "playwright"], | ||
help="Select testing frameworks, selenium or playwright (default: %(default)s)", | ||
) | ||
|
||
|
||
# Handling for pytest assertion rewrites | ||
# First we find the pytest rewrite config. It's an attribute of the pytest | ||
# assertion rewriting meta_path_finder, so we locate that to get the config. | ||
|
||
|
||
def _get_pytest_rewrite_config() -> Any: | ||
for meta_path_finder in sys.meta_path: | ||
if isinstance(meta_path_finder, AssertionRewritingHook): | ||
break | ||
else: | ||
return None | ||
return meta_path_finder.config | ||
|
||
|
||
# Now we need to parse the ast of the files, rewrite the ast, and store the | ||
# original and rewritten ast into dictionaries. `run_in_pyodide` will look the | ||
# ast up in the appropriate dictionary depending on whether or not it is using | ||
# pytest assert rewrites. | ||
|
||
REWRITE_CONFIG = _get_pytest_rewrite_config() | ||
del _get_pytest_rewrite_config | ||
|
||
ORIGINAL_MODULE_ASTS: dict[str, ast.Module] = {} | ||
REWRITTEN_MODULE_ASTS: dict[str, ast.Module] = {} | ||
|
||
|
||
def pytest_pycollect_makemodule(module_path: Path, path: Any, parent: Any) -> None: | ||
source = module_path.read_bytes() | ||
strfn = str(module_path) | ||
tree = ast.parse(source, filename=strfn) | ||
ORIGINAL_MODULE_ASTS[strfn] = tree | ||
tree2 = deepcopy(tree) | ||
rewrite_asserts(tree2, source, strfn, REWRITE_CONFIG) | ||
REWRITTEN_MODULE_ASTS[strfn] = tree2 | ||
orig_pytest_pycollect_makemodule(module_path, parent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.