Use pytest instead of nosetests
Nose has been in maintenance mode for the past several years and pytest is a good replacement. Other changes: - Replace deprecated assertRegexpMatches with assertRegex - Replace deprecated assertRaisesRegexp with assertRaisesRegex - Replace deprecated SafeConfigParser with ConfigParser - Force reinstall pytest and mock in tox virtualenv. This is because the globally installed packages may not work as expected(occured in jenkins job). JIRA: RHELCMP-1619 Signed-off-by: Haibo Lin <hlin@redhat.com>
This commit is contained in:
parent
495a4c48b2
commit
3c72755814
13 changed files with 51 additions and 54 deletions
|
|
@ -96,7 +96,7 @@ class CheckDependenciesTestCase(unittest.TestCase):
|
|||
exists.side_effect = self.dont_find(["/usr/bin/isohybrid"])
|
||||
result = checks.check(conf)
|
||||
|
||||
self.assertRegexpMatches(out.getvalue(), r"^Not checking.*Expect failures.*$")
|
||||
self.assertRegex(out.getvalue(), r"^Not checking.*Expect failures.*$")
|
||||
self.assertTrue(result)
|
||||
|
||||
def test_isohybrid_not_needed_in_runroot(self):
|
||||
|
|
@ -215,7 +215,7 @@ class TestSchemaValidator(unittest.TestCase):
|
|||
errors, warnings = checks.validate(config)
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertEqual(len(warnings), 1)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[0],
|
||||
r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*", # noqa: E501
|
||||
)
|
||||
|
|
@ -268,7 +268,7 @@ class TestSchemaValidator(unittest.TestCase):
|
|||
errors, warnings = checks.validate(config)
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertEqual(len(warnings), 1)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[0],
|
||||
r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*", # noqa: E501
|
||||
)
|
||||
|
|
@ -295,12 +295,12 @@ class TestSchemaValidator(unittest.TestCase):
|
|||
config = self._load_conf_from_string(string)
|
||||
errors, warnings = checks.validate(config)
|
||||
self.assertEqual(len(errors), 1)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
errors[0],
|
||||
r"^ERROR: Config option 'product_name' is an alias of 'release_name', only one can be used.*", # noqa: E501
|
||||
)
|
||||
self.assertEqual(len(warnings), 1)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[0],
|
||||
r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*", # noqa: E501
|
||||
)
|
||||
|
|
@ -337,11 +337,11 @@ class TestSchemaValidator(unittest.TestCase):
|
|||
errors, warnings = checks.validate(config)
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertEqual(len(warnings), 2)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[0],
|
||||
r"^WARNING: Config option '.+' is deprecated and now an alias to '.+'.*",
|
||||
)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[1],
|
||||
r"^WARNING: Config option '.+' is deprecated and now an alias to '.+'.*",
|
||||
)
|
||||
|
|
@ -382,11 +382,11 @@ class TestSchemaValidator(unittest.TestCase):
|
|||
errors, warnings = checks.validate(config)
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertEqual(len(warnings), 2)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[0],
|
||||
r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*", # noqa: E501
|
||||
)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[1],
|
||||
r"^WARNING: Value from config option 'repo_from' is now appended to option 'repo'", # noqa: E501
|
||||
)
|
||||
|
|
@ -424,11 +424,11 @@ class TestSchemaValidator(unittest.TestCase):
|
|||
errors, warnings = checks.validate(config)
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertEqual(len(warnings), 2)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[0],
|
||||
r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*", # noqa: E501
|
||||
)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[1],
|
||||
r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified,", # noqa: E501
|
||||
)
|
||||
|
|
@ -470,19 +470,19 @@ class TestSchemaValidator(unittest.TestCase):
|
|||
errors, warnings = checks.validate(config)
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertEqual(len(warnings), 4)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[0],
|
||||
r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*", # noqa: E501
|
||||
)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[1],
|
||||
r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified,", # noqa: E501
|
||||
)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[2],
|
||||
r"^WARNING: Config option 'source_repo_from' is deprecated, its value will be appended to option 'repo'", # noqa: E501
|
||||
)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[3],
|
||||
r"^WARNING: Value from config option 'source_repo_from' is now appended to option 'repo'.", # noqa: E501
|
||||
)
|
||||
|
|
@ -532,11 +532,11 @@ class TestSchemaValidator(unittest.TestCase):
|
|||
errors, warnings = checks.validate(config)
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertEqual(len(warnings), 2)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[0],
|
||||
r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*", # noqa: E501
|
||||
)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
warnings[1],
|
||||
r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified, value from 'repo_from' is now added as 'repo'.*", # noqa: E501
|
||||
)
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ class ComposeTestCase(unittest.TestCase):
|
|||
def test_setup_logger(self, ci):
|
||||
conf = {}
|
||||
logger = logging.getLogger("test_setup_logger")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
compose = Compose(conf, self.tmp_dir, logger=logger)
|
||||
self.assertEqual(len(logger.handlers), 2)
|
||||
|
||||
|
|
|
|||
|
|
@ -1341,7 +1341,7 @@ class TestGetProductIds(PungiTestCase):
|
|||
get_productids_from_scm(self.compose)
|
||||
|
||||
self.assertEqual(get_dir_from_scm.call_args_list, [mock.call(cfg, mock.ANY)])
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
str(ctx.exception),
|
||||
r"No product certificate found \(arch: amd64, variant: (Everything|Client)\)", # noqa: E501
|
||||
)
|
||||
|
|
@ -1365,6 +1365,4 @@ class TestGetProductIds(PungiTestCase):
|
|||
get_productids_from_scm(self.compose)
|
||||
|
||||
self.assertEqual(get_dir_from_scm.call_args_list, [mock.call(cfg, mock.ANY)])
|
||||
self.assertRegexpMatches(
|
||||
str(ctx.exception), "Multiple product certificates found.+"
|
||||
)
|
||||
self.assertRegex(str(ctx.exception), "Multiple product certificates found.+")
|
||||
|
|
|
|||
|
|
@ -244,9 +244,7 @@ class TestCopyFiles(helpers.PungiTestCase):
|
|||
self.compose, [cfg], "x86_64", self.variant, package_sets, self.metadata
|
||||
)
|
||||
|
||||
self.assertRegexpMatches(
|
||||
str(ctx.exception), r"No.*package.*matching bad-server\*.*"
|
||||
)
|
||||
self.assertRegex(str(ctx.exception), r"No.*package.*matching bad-server\*.*")
|
||||
|
||||
self.assertEqual(len(get_file_from_scm.call_args_list), 0)
|
||||
self.assertEqual(get_dir_from_scm.call_args_list, [])
|
||||
|
|
|
|||
|
|
@ -363,7 +363,7 @@ class TestLiveMediaPhase(PungiTestCase):
|
|||
|
||||
phase = LiveMediaPhase(compose)
|
||||
|
||||
with self.assertRaisesRegexp(
|
||||
with self.assertRaisesRegex(
|
||||
RuntimeError, r"no.+Missing.+when building.+Server"
|
||||
):
|
||||
phase.run()
|
||||
|
|
@ -393,7 +393,7 @@ class TestLiveMediaPhase(PungiTestCase):
|
|||
|
||||
phase = LiveMediaPhase(compose)
|
||||
|
||||
with self.assertRaisesRegexp(
|
||||
with self.assertRaisesRegex(
|
||||
RuntimeError, r"There is no variant Missing to get repo from."
|
||||
):
|
||||
phase.run()
|
||||
|
|
|
|||
|
|
@ -550,9 +550,7 @@ class OSBSThreadTest(helpers.PungiTestCase):
|
|||
with self.assertRaises(RuntimeError) as ctx:
|
||||
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
||||
|
||||
self.assertRegexpMatches(
|
||||
str(ctx.exception), r"task 12345 failed: see .+ for details"
|
||||
)
|
||||
self.assertRegex(str(ctx.exception), r"task 12345 failed: see .+ for details")
|
||||
|
||||
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
||||
def test_failing_task_with_failable(self, KojiWrapper):
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ class TestKojiPkgset(PkgsetCompareMixin, helpers.PungiTestCase):
|
|||
r"^RPM\(s\) not found for sigs: .+Check log for details.+bash-4\.3\.42-4\.fc24.+bash-debuginfo-4\.3\.42-4\.fc24$", # noqa: E501
|
||||
re.DOTALL,
|
||||
)
|
||||
self.assertRegexpMatches(str(ctx.exception), figure)
|
||||
self.assertRegex(str(ctx.exception), figure)
|
||||
|
||||
def test_can_not_find_signed_package_allow_invalid_sigkeys(self):
|
||||
pkgset = pkgsets.KojiPackageSet(
|
||||
|
|
@ -326,7 +326,7 @@ class TestKojiPkgset(PkgsetCompareMixin, helpers.PungiTestCase):
|
|||
r"^RPM\(s\) not found for sigs: .+Check log for details.+bash-4\.3\.42-4\.fc24.+bash-debuginfo-4\.3\.42-4\.fc24$", # noqa: E501
|
||||
re.DOTALL,
|
||||
)
|
||||
self.assertRegexpMatches(str(ctx.exception), figure)
|
||||
self.assertRegex(str(ctx.exception), figure)
|
||||
|
||||
def test_can_not_find_any_package(self):
|
||||
pkgset = pkgsets.KojiPackageSet(
|
||||
|
|
@ -341,7 +341,7 @@ class TestKojiPkgset(PkgsetCompareMixin, helpers.PungiTestCase):
|
|||
[mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)],
|
||||
)
|
||||
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
str(ctx.exception),
|
||||
r"^RPM\(s\) not found for sigs: .+Check log for details.+",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import mock
|
|||
import os
|
||||
import shutil
|
||||
import six
|
||||
from six.moves.configparser import SafeConfigParser
|
||||
from six.moves.configparser import ConfigParser
|
||||
|
||||
from tests.helpers import PungiTestCase, FIXTURE_DIR, touch, mk_boom
|
||||
from pungi_utils import unified_isos
|
||||
|
|
@ -24,7 +24,7 @@ class TestUnifiedIsos(PungiTestCase):
|
|||
compose_path = os.path.join(self.topdir, COMPOSE_ID, "compose")
|
||||
isos = unified_isos.UnifiedISO(compose_path)
|
||||
self.assertEqual(isos.compose_path, compose_path)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
isos.temp_dir, "^%s/" % os.path.join(self.topdir, COMPOSE_ID, "work")
|
||||
)
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ class TestUnifiedIsos(PungiTestCase):
|
|||
self.assertEqual(
|
||||
isos.compose_path, os.path.join(self.topdir, COMPOSE_ID, "compose")
|
||||
)
|
||||
self.assertRegexpMatches(
|
||||
self.assertRegex(
|
||||
isos.temp_dir, "^%s/" % os.path.join(self.topdir, COMPOSE_ID, "work")
|
||||
)
|
||||
|
||||
|
|
@ -399,7 +399,7 @@ class TestCreaterepo(PungiTestCase):
|
|||
|
||||
# treeinfo checksums
|
||||
for arch in self.isos.treeinfo.keys():
|
||||
parser = SafeConfigParser()
|
||||
parser = ConfigParser()
|
||||
parser.optionxform = str
|
||||
parser.read(os.path.join(self.isos.temp_dir, "trees", arch, ".treeinfo"))
|
||||
checksums[arch] = [k for k, v in parser.items("checksums")]
|
||||
|
|
@ -489,7 +489,7 @@ class TestCreaterepo(PungiTestCase):
|
|||
|
||||
# treeinfo checksums
|
||||
for arch in self.isos.treeinfo.keys():
|
||||
parser = SafeConfigParser()
|
||||
parser = ConfigParser()
|
||||
parser.optionxform = str
|
||||
parser.read(os.path.join(self.isos.temp_dir, "trees", arch, ".treeinfo"))
|
||||
checksums[arch] = [k for k, v in parser.items("checksums")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue