Merge lp:~verterok/ols-tests/feature-handle-failing-probe into lp:ols-tests

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: 226
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~verterok/ols-tests/feature-handle-failing-probe
Merge into: lp:ols-tests
Diff against target: 41 lines (+20/-1)
2 files modified
olstests/features.py (+5/-1)
olstests/tests/test_features.py (+15/-0)
To merge this branch: bzr merge lp:~verterok/ols-tests/feature-handle-failing-probe
Reviewer Review Type Date Requested Status
Daniel Manrique (community) Approve
Review via email: mp+442136@code.launchpad.net

Commit message

Handle failing probe in Feature.available

Feature availability is evaluated on import, if the probe fails with an exception the test run is interrupted instead of marking the feature as not available

To post a comment you must log in.
Revision history for this message
Daniel Manrique (roadmr) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'olstests/features.py'
2--- olstests/features.py 2016-02-08 17:54:01 +0000
3+++ olstests/features.py 2023-05-01 10:10:02 +0000
4@@ -32,7 +32,11 @@
5 :return: True if the feature is available.
6 """
7 if self._available is None:
8- self._available = self._probe()
9+ try:
10+ self._available = self._probe()
11+ except Exception:
12+ # if the _probe fails, mark this as not available
13+ self._available = False
14 return self._available
15
16 def _probe(self):
17
18=== modified file 'olstests/tests/test_features.py'
19--- olstests/tests/test_features.py 2016-02-08 17:54:01 +0000
20+++ olstests/tests/test_features.py 2023-05-01 10:10:02 +0000
21@@ -66,6 +66,21 @@
22 feature = NamedFeature()
23 self.assertEqual('NamedFeature', unicode(feature))
24
25+ def test_failing_probe(self):
26+
27+ class FailingFeature(features.Feature):
28+ def __init__(self):
29+ super(FailingFeature, self).__init__()
30+ self.calls = []
31+
32+ def _probe(self):
33+ self.calls.append('_probe')
34+ raise OSError('No such file')
35+
36+ feature = FailingFeature()
37+ self.assertFalse(feature.available())
38+ self.assertEqual(['_probe'], feature.calls)
39+
40
41 class TestUbuntuPlatformFeature(unittest.TestCase):
42

Subscribers

People subscribed via source and target branches