mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-29 21:21:14 +08:00
Use a context manager to patch sys.modules
When not using the context manager, it causes the pytest process to not close after the tests have completed when the tests are run using Python 3.
This commit is contained in:
@@ -202,7 +202,6 @@ class TestBuild:
|
||||
with io.open(path.join(dir_path, "modulemd.i686.txt"), encoding="utf-8") as mmd:
|
||||
assert len(mmd.read()) == 254
|
||||
|
||||
@patch.dict("sys.modules", krbV=Mock())
|
||||
@patch("koji.ClientSession")
|
||||
def test_tag_cg_build(self, ClientSession):
|
||||
""" Test that the CG build is tagged. """
|
||||
@@ -210,7 +209,8 @@ class TestBuild:
|
||||
koji_session.getUser.return_value = GET_USER_RV
|
||||
koji_session.getTag.return_value = {"id": 123}
|
||||
|
||||
self.cg._tag_cg_build()
|
||||
with patch.dict("sys.modules", krbV=Mock()):
|
||||
self.cg._tag_cg_build()
|
||||
|
||||
koji_session.getTag.assert_called_once_with(self.cg.module.cg_build_koji_tag)
|
||||
koji_session.tagBuild.assert_called_once_with(123, "nginx-0-2.10e50d06")
|
||||
@@ -218,7 +218,6 @@ class TestBuild:
|
||||
# tagBuild requires logging into a session in advance.
|
||||
koji_session.krb_login.assert_called_once()
|
||||
|
||||
@patch.dict("sys.modules", krbV=Mock())
|
||||
@patch("koji.ClientSession")
|
||||
def test_tag_cg_build_fallback_to_default_tag(self, ClientSession):
|
||||
""" Test that the CG build is tagged to default tag. """
|
||||
@@ -226,7 +225,8 @@ class TestBuild:
|
||||
koji_session.getUser.return_value = GET_USER_RV
|
||||
koji_session.getTag.side_effect = [{}, {"id": 123}]
|
||||
|
||||
self.cg._tag_cg_build()
|
||||
with patch.dict("sys.modules", krbV=Mock()):
|
||||
self.cg._tag_cg_build()
|
||||
|
||||
assert koji_session.getTag.mock_calls == [
|
||||
call(self.cg.module.cg_build_koji_tag),
|
||||
@@ -237,7 +237,6 @@ class TestBuild:
|
||||
# tagBuild requires logging into a session in advance.
|
||||
koji_session.krb_login.assert_called_once()
|
||||
|
||||
@patch.dict("sys.modules", krbV=Mock())
|
||||
@patch("koji.ClientSession")
|
||||
def test_tag_cg_build_no_tag_set(self, ClientSession):
|
||||
""" Test that the CG build is not tagged when no tag set. """
|
||||
@@ -246,13 +245,13 @@ class TestBuild:
|
||||
koji_session.getTag.side_effect = [{}, {"id": 123}]
|
||||
|
||||
self.cg.module.cg_build_koji_tag = None
|
||||
self.cg._tag_cg_build()
|
||||
with patch.dict("sys.modules", krbV=Mock()):
|
||||
self.cg._tag_cg_build()
|
||||
|
||||
koji_session.tagBuild.assert_not_called()
|
||||
# tagBuild requires logging into a session in advance.
|
||||
koji_session.krb_login.assert_called_once()
|
||||
|
||||
@patch.dict("sys.modules", krbV=Mock())
|
||||
@patch("koji.ClientSession")
|
||||
def test_tag_cg_build_no_tag_available(self, ClientSession):
|
||||
""" Test that the CG build is not tagged when no tag available. """
|
||||
@@ -260,7 +259,8 @@ class TestBuild:
|
||||
koji_session.getUser.return_value = GET_USER_RV
|
||||
koji_session.getTag.side_effect = [{}, {}]
|
||||
|
||||
self.cg._tag_cg_build()
|
||||
with patch.dict("sys.modules", krbV=Mock()):
|
||||
self.cg._tag_cg_build()
|
||||
|
||||
koji_session.tagBuild.assert_not_called()
|
||||
# tagBuild requires logging into a session in advance.
|
||||
@@ -963,7 +963,6 @@ class TestBuild:
|
||||
requires.append("%s:%s" % (name, stream))
|
||||
assert "%s:%s" % (mmd.get_module_name(), mmd.get_stream_name()) in requires
|
||||
|
||||
@patch.dict("sys.modules", krbV=Mock())
|
||||
@patch("koji.ClientSession")
|
||||
@patch("module_build_service.builder.KojiContentGenerator.KojiContentGenerator._tag_cg_build")
|
||||
@patch("module_build_service.builder.KojiContentGenerator.KojiContentGenerator._load_koji_tag")
|
||||
@@ -971,7 +970,8 @@ class TestBuild:
|
||||
""" Tests whether build is still tagged even if there's an exception in CGImport """
|
||||
cl_session.return_value.CGImport = Mock(
|
||||
side_effect=koji.GenericError("Build already exists asdv"))
|
||||
self.cg.koji_import()
|
||||
with patch.dict("sys.modules", krbV=Mock()):
|
||||
self.cg.koji_import()
|
||||
tagger.assert_called()
|
||||
|
||||
def test_fill_in_rpms_list_debuginfo_deps(self):
|
||||
|
||||
Reference in New Issue
Block a user