Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIx #400 Stdout feedback if test skipped #440

Merged
merged 16 commits into from
Feb 12, 2024
6 changes: 6 additions & 0 deletions pykern/pkcli/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

SUITE_D = "tests"
_COROUTINE_NEVER_AWAITED = re.compile("RuntimeWarning: coroutine .+ was never awaited")
_TEST_SKIPPED = re.compile(r"^.+\s+SKIPPED\s+\(.+\)$", flags=re.MULTILINE)
_FAILED_ON_WARNINGS = "\n*** FAILED due to warnings. See warnings summary ***\n"
_TEST_PY = re.compile(r"_test\.py$")

Expand Down Expand Up @@ -170,6 +171,9 @@ def _except(exc, output, restartable):
return "restart"
return _fail(output)

def _skipped(ouput):
return _TEST_SKIPPED.findall(ouput)

def _fail(output):
self.failures.append(output)
return f"FAIL {output}"
Expand All @@ -187,6 +191,8 @@ def _try(output, restartable):
if _COROUTINE_NEVER_AWAITED.search(o):
pkio.write_text(output, o + _FAILED_ON_WARNINGS)
return _fail(output)
if _TEST_SKIPPED.search(o):
return "\n".join(["pass"] + _skipped(o))
return "pass"
except Exception as e:
return _except(e, output, restartable)
Expand Down
17 changes: 17 additions & 0 deletions tests/pkcli/test_data/tests/3_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""test pytest skip

:copyright: Copyright (c) 2024 RadiaSoft LLC. All Rights Reserved.
:license: http://www.apache.org/licenses/LICENSE-2.0.html
"""
import pytest


@pytest.mark.skip(reason="always skips")
def test_skip():
from pykern import pkunit

pkunit.pkfail("test_skip not skipped")


def test_pass():
pass
37 changes: 30 additions & 7 deletions tests/pkcli/test_test.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,70 @@
# -*- coding: utf-8 -*-
"""pkcli.test test

:copyright: Copyright (c) 2019 RadiaSoft LLC. All Rights Reserved.
:license: http://www.apache.org/licenses/LICENSE-2.0.html
"""


def setup_module(module):
import os

# Our CI (radiasoft/download/installers/python-ci sets these to 1,
# but we do not want restarts or to stop out due to max failures
os.environ.update(
PYKERN_PKCLI_TEST_MAX_FAILURES="5",
PYKERN_PKCLI_TEST_RESTARTABLE="0",
)


def test_simple(capsys):
from pykern import pkunit
from pykern.pkcli import test

with pkunit.save_chdir_work() as d:
t = d.join("tests")
pkunit.data_dir().join("tests").copy(t)
with pkunit.pkexcept("FAILED=1 passed=1"):
with pkunit.pkexcept("FAILED=1 passed=2", "all tests"):
test.default_command()
o, e = capsys.readouterr()
pkunit.pkre("1_test.py pass", o)
pkunit.pkre("2_test.py FAIL", o)
t.join("2_test.py").rename(t.join("2_test.py-"))
pkunit.pkre("passed=1", test.default_command())
# tests 1 & 3 together
pkunit.pkre("passed=2", test.default_command())
o, e = capsys.readouterr()
pkunit.pkre("1_test.py pass", o)
pkunit.pkre(
"3_test.py pass\ntests/3_test.py::test_skip SKIPPED .always skips.",
o,
)
# tests 1 and 3 individually
pkunit.pkre("passed=1", test.default_command("tests/1_test.py"))
o, e = capsys.readouterr()
pkunit.pkre("1_test.py pass", o)
pkunit.pkre("passed=1", test.default_command("tests/3_test.py"))
o, e = capsys.readouterr()
pkunit.pkre("3_test.py pass.*test_skip SKIPPED", o)
# test 2 and 3 together
t.join("2_test.py-").rename(t.join("2_test.py"))
t.join("1_test.py").rename(t.join("1_test.py-"))
with pkunit.pkexcept("FAILED=1 passed=0"):
with pkunit.pkexcept("FAILED=1 passed=1"):
test.default_command()
o, e = capsys.readouterr()
pkunit.pkre("2_test.py FAIL", o)
pkunit.pkre("x = 1 / 0", o)
pkunit.pkre("test_skip SKIPPED", o)


def test_tests_dir():
def test_tests_dir(capsys):
from pykern import pkio, pkdebug
from pykern import pkunit
from pykern.pkcli import test

with pkunit.save_chdir_work() as d:
pkunit.data_dir().join("tests").copy(d.join("tests"))
with pkunit.pkexcept("FAILED=1 passed=1"):
with pkunit.pkexcept("FAILED=1 passed=2"):
test.default_command()
with pkunit.pkexcept("FAILED=1 passed=0"):
with pkunit.pkexcept("FAILED=1 passed=1"):
test.default_command("skip_past=1_test")
# to avoid confusing output with SKIPPED
capsys.readouterr()
Loading