summaryrefslogtreecommitdiff
path: root/tests/checkers/unittest_refactoring.py
diff options
context:
space:
mode:
authorSergey B Kirpichev <skirpichev@gmail.com>2022-03-18 06:16:23 +0300
committerDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2022-03-18 09:05:15 +0100
commit9baa5b228a3c111a42edef026615f3d9584c63df (patch)
treebeef2390b352e70a0e1f087f863b7ae3c3962a2c /tests/checkers/unittest_refactoring.py
parentccd32d32c7362f15d43ee83b3ac82b405eb049bf (diff)
downloadpylint-git-9baa5b228a3c111a42edef026615f3d9584c63df.tar.gz
Use pytest-timeout for tests
Diffstat (limited to 'tests/checkers/unittest_refactoring.py')
-rw-r--r--tests/checkers/unittest_refactoring.py44
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