Repository: pyodide/pytest-pyodide (language: python)

Issue:
add pytest extra args option
This adds an option to the reusable main action for extra args to pass to pytest. Without that it isn't possible to e.g. filter out non-pyodide test python files.


Discussion / hints:
What's the status of this PR? Do we still want it or is now handled by `pyodide-actions` repo?
I'll open a PR that fixes the failing test suite, then we can merge this. This isn't related to pyodide-actions I think.

Fix patch:
diff --git a/.github/workflows/filtermatrix.py b/.github/workflows/filtermatrix.py
index bb88474c..82247c19 100644
--- a/.github/workflows/filtermatrix.py
+++ b/.github/workflows/filtermatrix.py
@@ -26,11 +26,6 @@
     {runner: selenium, browser: node, browser-version: 16},
     {runner: selenium, browser: node, browser-version: 18},
     {runner: selenium, browser: firefox-no-host, browser-version: latest, driver-version: latest },
-    {
-    runner: selenium, browser: chrome firefox,
-    browser-version: latest, browser-version: latest,
-    browser-version: latest, browser-version: latest,
-    },
     {runner: selenium, browser: host},
     # playwright browser versions are pinned to playwright version
     {runner: playwright, browser: firefox, runner-version: 1.22.0, driver-version: 18},


Test patch:
diff --git a/conftest.py b/conftest.py
index 888492ad..48414c7c 100644
--- a/conftest.py
+++ b/conftest.py
@@ -1,4 +1,5 @@
 pytest_plugins = [
     "pytest_pyodide.hook",
     "pytest_pyodide.fixture",
+    "pytester",
 ]
diff --git a/tests/test_options.py b/tests/test_options.py
new file mode 100644
index 00000000..e7186d2c
--- /dev/null
+++ b/tests/test_options.py
@@ -0,0 +1,75 @@
+import pytest
+
+
+def test_dist_dir(pytester):
+
+    dist_dir = "dist"
+
+    pytester.makepyfile(
+        f"""
+        import pytest
+        def test_option(request):
+            assert str(request.config.getoption("--dist-dir", "")) == {dist_dir!r}
+        """
+    )
+
+    result = pytester.runpytest("--dist-dir", dist_dir)
+    result.assert_outcomes(passed=1)
+
+
+@pytest.mark.parametrize("runner", ["selenium", "playwright"])
+def test_runner(pytester, runner):
+    pytester.makepyfile(
+        f"""
+        import pytest
+        def test_option(request):
+            assert request.config.getoption("--runner") == {runner!r}
+        """
+    )
+
+    result = pytester.runpytest("--runner", runner)
+    result.assert_outcomes(passed=1)
+
+
+def test_invalid_runner(pytester):
+
+    runner = "blah"
+
+    pytester.makepyfile(
+        f"""
+        import pytest
+        def test_option(request):
+            assert request.config.getoption("--runner") == {runner!r}
+        """
+    )
+
+    result = pytester.runpytest("--runner", runner)
+
+    # pytest: error argument --runner: invalid choice ...
+    assert result.ret == 4
+
+
+@pytest.mark.parametrize(
+    "_runtime",
+    [
+        "chrome",
+        "firefox",
+        "safari",
+        "node",
+        "firefox chrome",
+    ],
+)
+def test_runtime(pytester, _runtime):
+
+    runtimes = _runtime.split()
+
+    pytester.makepyfile(
+        f"""
+        import pytest
+        def test_option(request):
+            assert request.config.getoption("--runtime") == {runtimes!r}
+        """
+    )
+
+    result = pytester.runpytest("--runtime", *runtimes)
+    result.assert_outcomes(passed=1)