-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pytest and pygame-ce tests (#45)
- Loading branch information
1 parent
fc3797d
commit 5157757
Showing
2 changed files
with
43 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,41 @@ | ||
def test_pytest(selenium): | ||
# TODO: don't use numpy in this test as it's not necessarily installed. | ||
selenium.load_package(["pytest", "numpy"]) | ||
from pytest_pyodide import run_in_pyodide | ||
|
||
|
||
@run_in_pyodide(packages=["pytest"]) | ||
def do_test(selenium, contents): | ||
from contextlib import redirect_stdout | ||
from io import StringIO | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
Path("test_pytest.py").write_text(contents) | ||
|
||
selenium.run( | ||
""" | ||
from pathlib import Path | ||
import os | ||
import numpy | ||
import pytest | ||
out = StringIO() | ||
with redirect_stdout(out): | ||
result = pytest.main(["test_pytest.py"]) | ||
|
||
assert result == 1 | ||
|
||
out.seek(0) | ||
output = out.read() | ||
assert "2 passed" in output, output | ||
assert "1 failed" in output, output | ||
assert "1 warning" in output, output | ||
assert "This is a warning" in output, output | ||
|
||
|
||
def test_pytest(selenium): | ||
contents = """ | ||
def test_success(): | ||
assert 1 == 1 | ||
base_dir = Path(numpy.__file__).parent / "core" / "tests" | ||
""" | ||
) | ||
def test_warning(): | ||
import warnings | ||
warnings.warn("This is a warning") | ||
selenium.run("pytest.main([str(base_dir / 'test_api.py')])") | ||
def test_fail(): | ||
assert 1 == 2 | ||
""" | ||
|
||
logs = "\n".join(selenium.logs) | ||
assert "INTERNALERROR" not in logs | ||
do_test(selenium, contents) |