Fail the tests that skipped at run time, naming what they miss, and give CI's tests docker
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import contextlib
|
||||
import importlib.util
|
||||
import io
|
||||
from unittest import mock
|
||||
import os
|
||||
@@ -14,10 +13,8 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
from run_tests import main
|
||||
|
||||
BIN = pathlib.Path(__file__).resolve().parents[1]
|
||||
# The suite runs under pytest, and `python3 -m unittest` may run it where pytest is not installed.
|
||||
HAS_PYTEST = importlib.util.find_spec("pytest") is not None
|
||||
HAS_XDIST = importlib.util.find_spec("xdist") is not None
|
||||
PYTEST_HERE = [sys.executable, "-m", "pytest", "-p", "no:cacheprovider"]
|
||||
# The pytest and pytest-xdist run-tests pins, without its worker count, so the tests run them whether or not the interpreter running the tests has pytest.
|
||||
PYTEST_PINNED = [*main.PYTEST[:main.PYTEST.index("-n")], "-p", "no:cacheprovider"]
|
||||
|
||||
|
||||
class PytestArgs(unittest.TestCase):
|
||||
@@ -109,7 +106,6 @@ class RunWithAStandIn(unittest.TestCase):
|
||||
self.assertEqual(err.getvalue(), "run-tests: cannot start /no/such/uvx: No such file or directory\n")
|
||||
|
||||
|
||||
@unittest.skipUnless(HAS_PYTEST, "needs pytest importable")
|
||||
class Run(unittest.TestCase):
|
||||
def run_in(self, folder: str, pytest: list[str], *args: str) -> tuple[int, str]:
|
||||
out = io.StringIO()
|
||||
@@ -127,7 +123,7 @@ class Run(unittest.TestCase):
|
||||
def test_a_passing_run_prints_the_summary_line_and_the_log_path(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
pathlib.Path(folder, "test_ok.py").write_text("def test_ok():\n\tprint('noise from a passing test')\n")
|
||||
code, output = self.run_in(folder, PYTEST_HERE, "-s", folder)
|
||||
code, output = self.run_in(folder, PYTEST_PINNED, "-s", folder)
|
||||
self.assertEqual(code, 0)
|
||||
lines = output.rstrip("\n").splitlines()
|
||||
self.assertEqual(len(lines), 2, output)
|
||||
@@ -136,10 +132,9 @@ class Run(unittest.TestCase):
|
||||
|
||||
def test_a_failing_run_prints_each_failing_test_with_its_error(self):
|
||||
# pytest-xdist drops the error from the short summary's lines, so the run takes it from the FAILURES section.
|
||||
workers = ["-n", "2"] if HAS_XDIST else []
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
pathlib.Path(folder, "test_bad.py").write_text("def test_ok():\n\tpass\n\ndef test_bad():\n\tassert 1 == 2, 'one is not two'\n\ndef test_long():\n\traise ValueError('\\n'.join(map(str, range(30))))\n")
|
||||
code, output = self.run_in(folder, PYTEST_HERE, *workers, folder)
|
||||
code, output = self.run_in(folder, PYTEST_PINNED, "-n", "2", folder)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertRegex(output, r"(?m)^_+ test_bad _+\nE +AssertionError: one is not two\n(E .*\n)*.*test_bad\.py:5: AssertionError$")
|
||||
self.assertRegex(output, r"(?m)^FAILED .*test_bad\.py::test_bad\b")
|
||||
@@ -158,7 +153,7 @@ class Run(unittest.TestCase):
|
||||
|
||||
def test_a_run_that_prints_no_summary_line_shows_the_logs_last_lines(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
code, output = self.run_in(folder, PYTEST_HERE, "--no-such-option", folder)
|
||||
code, output = self.run_in(folder, PYTEST_PINNED, "--no-such-option", folder)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("run-tests: pytest printed no summary line; the log ends:", output)
|
||||
self.assertIn("--no-such-option", output)
|
||||
|
||||
Reference in New Issue
Block a user