diff options
author | Sergey B Kirpichev <skirpichev@gmail.com> | 2022-03-18 06:16:23 +0300 |
---|---|---|
committer | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-03-18 09:05:15 +0100 |
commit | 9baa5b228a3c111a42edef026615f3d9584c63df (patch) | |
tree | beef2390b352e70a0e1f087f863b7ae3c3962a2c /tests/checkers/unittest_refactoring.py | |
parent | ccd32d32c7362f15d43ee83b3ac82b405eb049bf (diff) | |
download | pylint-git-9baa5b228a3c111a42edef026615f3d9584c63df.tar.gz |
Use pytest-timeout for tests
Diffstat (limited to 'tests/checkers/unittest_refactoring.py')
-rw-r--r-- | tests/checkers/unittest_refactoring.py | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/tests/checkers/unittest_refactoring.py b/tests/checkers/unittest_refactoring.py index 760eb2fe8..86ed28a4d 100644 --- a/tests/checkers/unittest_refactoring.py +++ b/tests/checkers/unittest_refactoring.py @@ -2,8 +2,6 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE import os -import signal -from contextlib import contextmanager import pytest @@ -14,36 +12,22 @@ PARENT_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) REGR_DATA = os.path.join(PARENT_DIR, "regrtest_data") -@contextmanager -def timeout(timeout_s: float): - def _handle(_signum, _frame): - pytest.fail("Test took too long") - - signal.signal(signal.SIGALRM, _handle) - signal.setitimer(signal.ITIMER_REAL, timeout_s) - yield - signal.setitimer(signal.ITIMER_REAL, 0) - signal.signal(signal.SIGALRM, signal.SIG_DFL) - - -@pytest.mark.skipif(not hasattr(signal, "setitimer"), reason="Assumes POSIX signals") +@pytest.mark.timeout(8) def test_process_tokens() -> None: - with timeout(8.0): - with pytest.raises(SystemExit) as cm: - Run([os.path.join(REGR_DATA, "very_long_line.py")], reporter=TextReporter()) - assert cm.value.code == 0 + with pytest.raises(SystemExit) as cm: + Run([os.path.join(REGR_DATA, "very_long_line.py")], reporter=TextReporter()) + assert cm.value.code == 0 -@pytest.mark.skipif(not hasattr(signal, "setitimer"), reason="Assumes POSIX signals") +@pytest.mark.timeout(25) def test_issue_5724() -> None: """Regression test for parsing of pylint disable pragma's.""" - with timeout(25.0): - with pytest.raises(SystemExit) as cm: - Run( - [ - os.path.join(REGR_DATA, "issue_5724.py"), - "--enable=missing-final-newline", - ], - reporter=TextReporter(), - ) - assert cm.value.code == 0 + with pytest.raises(SystemExit) as cm: + Run( + [ + os.path.join(REGR_DATA, "issue_5724.py"), + "--enable=missing-final-newline", + ], + reporter=TextReporter(), + ) + assert cm.value.code == 0 |