From 25114f5de239329cbf78541ac969716228482964 Mon Sep 17 00:00:00 2001 From: Ben Greiner Date: Sun, 7 Feb 2021 12:58:28 +0100 Subject: [PATCH] use pytest-timeout for rlocus test --- .github/workflows/control-slycot-src.yml | 2 +- .github/workflows/python-package-conda.yml | 2 +- control/tests/rlocus_test.py | 10 ++-------- setup.py | 3 +++ 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/control-slycot-src.yml b/.github/workflows/control-slycot-src.yml index 41d56bf4a..5c55eea73 100644 --- a/.github/workflows/control-slycot-src.yml +++ b/.github/workflows/control-slycot-src.yml @@ -19,7 +19,7 @@ jobs: sudo apt install -y xvfb # Install test tools - conda install pip pytest + conda install pip pytest pytest-timeout # Install python-control dependencies conda install numpy matplotlib scipy diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index 6ab0ffb76..67f782048 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -32,7 +32,7 @@ jobs: sudo apt install -y xvfb # Install test tools - conda install pip coverage pytest + conda install pip coverage pytest pytest-timeout pip install coveralls # Install python-control dependencies diff --git a/control/tests/rlocus_test.py b/control/tests/rlocus_test.py index 799d45784..aa25cd2b7 100644 --- a/control/tests/rlocus_test.py +++ b/control/tests/rlocus_test.py @@ -76,6 +76,7 @@ def test_root_locus_zoom(self): assert_array_almost_equal(zoom_x, zoom_x_valid) assert_array_almost_equal(zoom_y, zoom_y_valid) + @pytest.mark.timeout(2) def test_rlocus_default_wn(self): """Check that default wn calculation works properly""" # @@ -94,12 +95,5 @@ def test_rlocus_default_wn(self): sys = ct.tf(*sp.signal.zpk2tf( [-1e-2, 1-1e7j, 1+1e7j], [0, -1e7j, 1e7j], 1)) - # Set up a timer to catch execution time - def signal_handler(signum, frame): - raise Exception("rlocus took too long to complete") - signal.signal(signal.SIGALRM, signal_handler) - - # Run the command and reset the alarm - signal.alarm(2) # 2 second timeout ct.root_locus(sys) - signal.alarm(0) # reset the alarm + diff --git a/setup.py b/setup.py index fcf2d740b..849d30b34 100644 --- a/setup.py +++ b/setup.py @@ -44,4 +44,7 @@ install_requires=['numpy', 'scipy', 'matplotlib'], + extras_require={ + 'test': ['pytest', 'pytest-timeout'], + } )