Poison netifaces.interfaces() in tests
While reviewing [1] it was noted that we've probably been invoking the real netifaces.interfaces() in some test paths. This isn't good, so introduce a fixture that blows up any test that does that. (NB: during development, the netifaces.interfaces()-specific poison fixture evolved into a generic fixture that can be extended in the future to poison anything in a similar fashion.) [1] https://review.opendev.org/#/c/671471/ Change-Id: I1fea14d5be10bb4e884f52e0ae8be722519ddd3f
This commit is contained in:
parent
7dfe999180
commit
2cc105b46a
|
@ -285,6 +285,8 @@ class TestCase(base.BaseTestCase):
|
|||
quota.UID_QFD_POPULATED_CACHE_BY_PROJECT = set()
|
||||
quota.UID_QFD_POPULATED_CACHE_ALL = False
|
||||
|
||||
self.useFixture(nova_fixtures.GenericPoisonFixture())
|
||||
|
||||
def _setup_cells(self):
|
||||
"""Setup a normal cellsv2 environment.
|
||||
|
||||
|
|
|
@ -2672,3 +2672,23 @@ class CyborgFixture(fixtures.Fixture):
|
|||
'nova.accelerator.cyborg._CyborgClient.'
|
||||
'delete_arqs_for_instance',
|
||||
side_effect=self.fake_delete_arqs_for_instance)).mock
|
||||
|
||||
|
||||
class GenericPoisonFixture(fixtures.Fixture):
|
||||
POISON_THESE = (
|
||||
('netifaces.interfaces',
|
||||
'a test environment should not be inspecting real interfaces on the '
|
||||
'test node'),
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
def poison_configure(method, reason):
|
||||
def fail(*a, **k):
|
||||
raise Exception('This test invokes %s, which is bad (%s); you '
|
||||
'should mock it.' % (method, reason))
|
||||
return fail
|
||||
|
||||
super(GenericPoisonFixture, self).setUp()
|
||||
for meth, why in self.POISON_THESE:
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
meth, poison_configure(meth, why)))
|
||||
|
|
Loading…
Reference in New Issue