From 3ab8f929841fc67dc6b545819946731e07425692 Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Dec 02 2021 22:51:03 +0000 Subject: switch from nose to pytest Nose upstream is abandoned. Switch to run the tests with pytest. --- diff --git a/devtools/containers/Dockerfile.centos8 b/devtools/containers/Dockerfile.centos8 index 86458b5..af7bf53 100644 --- a/devtools/containers/Dockerfile.centos8 +++ b/devtools/containers/Dockerfile.centos8 @@ -17,6 +17,7 @@ RUN \ python3-devel \ python3-librepo \ python3-pip \ + python3-pytest \ python3-rpm \ python3-tox \ redhat-rpm-config \ diff --git a/devtools/containers/Dockerfile.f32 b/devtools/containers/Dockerfile.f32 index 2e74e9c..5ede76b 100644 --- a/devtools/containers/Dockerfile.f32 +++ b/devtools/containers/Dockerfile.f32 @@ -15,6 +15,7 @@ RUN \ openssl-devel \ python3-devel \ python3-pip \ + python3-pytest \ python3-rpm \ python3-tox \ redhat-rpm-config \ diff --git a/devtools/containers/Dockerfile.f33 b/devtools/containers/Dockerfile.f33 index de552ac..afc13f4 100644 --- a/devtools/containers/Dockerfile.f33 +++ b/devtools/containers/Dockerfile.f33 @@ -15,6 +15,7 @@ RUN \ openssl-devel \ python3-devel \ python3-pip \ + python3-pytest \ python3-rpm \ python3-tox \ redhat-rpm-config \ diff --git a/devtools/containers/Dockerfile.f34 b/devtools/containers/Dockerfile.f34 index 2735a13..93991bc 100644 --- a/devtools/containers/Dockerfile.f34 +++ b/devtools/containers/Dockerfile.f34 @@ -15,6 +15,7 @@ RUN \ openssl-devel \ python3-devel \ python3-pip \ + python3-pytest \ python3-rpm \ python3-tox \ redhat-rpm-config \ diff --git a/devtools/containers/Dockerfile.rawhide b/devtools/containers/Dockerfile.rawhide index 3c961c7..7a1f153 100644 --- a/devtools/containers/Dockerfile.rawhide +++ b/devtools/containers/Dockerfile.rawhide @@ -15,6 +15,7 @@ RUN \ openssl-devel \ python3-devel \ python3-pip \ + python3-pytest \ python3-rpm \ python3-tox \ redhat-rpm-config \ diff --git a/docs/source/writing_koji_code.rst b/docs/source/writing_koji_code.rst index 267be2e..9da07fa 100644 --- a/docs/source/writing_koji_code.rst +++ b/docs/source/writing_koji_code.rst @@ -662,7 +662,7 @@ You will need to install the following packages to actually run the tests. * ``python3-dateutil`` * ``python3-mock`` * ``python3-multilib`` - * ``python3-nose`` + * ``python3-pytest`` * ``python3-psycopg2`` * ``python3-qpid-proton`` * ``python3-requests`` diff --git a/test-requirements.txt b/test-requirements.txt index 8f78224..71780e9 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -4,4 +4,4 @@ flake8-import-order mock<=2.0.0 requests-mock coverage -nose +pytest diff --git a/tests/test_cli/test_import_comps.py b/tests/test_cli/test_import_comps.py index 204eb73..66028ef 100644 --- a/tests/test_cli/test_import_comps.py +++ b/tests/test_cli/test_import_comps.py @@ -7,7 +7,7 @@ import json import mock import six -from nose.plugins.skip import SkipTest +from unittest import SkipTest try: import libcomps diff --git a/tests/test_hub/test_apply_query_opts.py b/tests/test_hub/test_apply_query_opts.py index c1f34a3..6b66803 100644 --- a/tests/test_hub/test_apply_query_opts.py +++ b/tests/test_hub/test_apply_query_opts.py @@ -1,6 +1,5 @@ import copy import unittest -from nose.tools import eq_ import kojihub @@ -16,7 +15,7 @@ class TestApplyQueryOpts(unittest.TestCase): opts = None expected = copy.copy(self.original) actual = kojihub._applyQueryOpts(self.original, opts) - eq_(expected, actual) + assert expected == actual def test_order_by_foo(self): opts = {'order': 'foo'} @@ -26,7 +25,7 @@ class TestApplyQueryOpts(unittest.TestCase): {'foo': 2, 'bar': -1}, ] actual = kojihub._applyQueryOpts(self.original, opts) - eq_(expected, actual) + assert expected == actual def test_order_by_bar(self): opts = {'order': 'bar'} @@ -36,7 +35,7 @@ class TestApplyQueryOpts(unittest.TestCase): {'foo': 1, 'bar': 1}, ] actual = kojihub._applyQueryOpts(self.original, opts) - eq_(expected, actual) + assert expected == actual def test_order_in_reverse(self): opts = {'order': '-foo'} @@ -46,7 +45,7 @@ class TestApplyQueryOpts(unittest.TestCase): {'foo': 0, 'bar': 0}, ] actual = kojihub._applyQueryOpts(self.original, opts) - eq_(expected, actual) + assert expected == actual def test_offset(self): opts = {'offset': 1} @@ -55,7 +54,7 @@ class TestApplyQueryOpts(unittest.TestCase): {'foo': 0, 'bar': 0}, ] actual = kojihub._applyQueryOpts(self.original, opts) - eq_(expected, actual) + assert expected == actual def test_limit(self): opts = {'limit': 2} @@ -64,7 +63,7 @@ class TestApplyQueryOpts(unittest.TestCase): {'foo': 2, 'bar': -1}, ] actual = kojihub._applyQueryOpts(self.original, opts) - eq_(expected, actual) + assert expected == actual def test_limit_and_offset(self): opts = {'limit': 1, 'offset': 1} @@ -72,15 +71,15 @@ class TestApplyQueryOpts(unittest.TestCase): {'foo': 2, 'bar': -1}, ] actual = kojihub._applyQueryOpts(self.original, opts) - eq_(expected, actual) + assert expected == actual def test_count_only(self): opts = {'countOnly': True} expected = 3 actual = kojihub._applyQueryOpts(self.original, opts) - eq_(expected, actual) + assert expected == actual opts = {'countOnly': True, 'offset': 2} expected = 1 actual = kojihub._applyQueryOpts(self.original, opts) - eq_(expected, actual) + assert expected == actual diff --git a/tests/test_hub/test_recycle_build.py b/tests/test_hub/test_recycle_build.py index 8a9749c..e84145c 100644 --- a/tests/test_hub/test_recycle_build.py +++ b/tests/test_hub/test_recycle_build.py @@ -1,4 +1,5 @@ import mock +import unittest import koji import kojihub @@ -6,10 +7,7 @@ import kojihub QP = kojihub.QueryProcessor UP = kojihub.UpdateProcessor -class TestRecycleBuild(): - # NOT a subclass of unittest.TestCase so that we can use generator - # methods - +class TestRecycleBuild(unittest.TestCase): def setUp(self): self.QueryProcessor = mock.patch('kojihub.QueryProcessor').start() self.UpdateProcessor = mock.patch('kojihub.UpdateProcessor', diff --git a/tests/test_lib/test_plugin.py b/tests/test_lib/test_plugin.py index b942755..feb4a1f 100644 --- a/tests/test_lib/test_plugin.py +++ b/tests/test_lib/test_plugin.py @@ -84,7 +84,7 @@ class TestCallbackDecorators(unittest.TestCase): self.assertEqual(newfunc(1, 2, 3), [1, 2, 3]) -class TestError(Exception): +class MyCustomError(Exception): """Raised by a test callback defined below""" pass @@ -103,12 +103,12 @@ class TestCallbacks(unittest.TestCase): self.callbacks.append([cbtype, args, kwargs]) def error_callback(self, cbtype, *args, **kwargs): - raise TestError + raise MyCustomError @koji.plugin.ignore_error def safe_error_callback(self, cbtype, *args, **kwargs): self.callbacks.append([cbtype, args, kwargs]) - raise TestError + raise MyCustomError @koji.plugin.convert_datetime def datetime_callback(self, cbtype, *args, **kwargs): @@ -299,8 +299,8 @@ class TestPluginTracker(unittest.TestCase): @mock.patch('logging.getLogger') def test_bad_plugin(self, getLogger): - self._set_module_side_effect(TestError) - with self.assertRaises(TestError): + self._set_module_side_effect(MyCustomError) + with self.assertRaises(MyCustomError): self.tracker.load('hello') self.assertEqual(self.tracker.get('hello'), None) getLogger.assert_called_once() diff --git a/tests/test_lib/test_policy.py b/tests/test_lib/test_policy.py index fe907fd..5daafb6 100644 --- a/tests/test_lib/test_policy.py +++ b/tests/test_lib/test_policy.py @@ -1,7 +1,7 @@ from __future__ import absolute_import import unittest -from nose.tools import raises +import pytest import koji.policy @@ -24,10 +24,10 @@ class myvarTest(koji.policy.CompareTest): class TestBasicTests(unittest.TestCase): - @raises(NotImplementedError) def test_base_test(self): - obj = koji.policy.BaseSimpleTest('something') - obj.run({}) + with pytest.raises(NotImplementedError): + obj = koji.policy.BaseSimpleTest('something') + obj.run({}) def test_true_test(self): obj = koji.policy.TrueTest('something') @@ -108,9 +108,9 @@ class TestBasicTests(unittest.TestCase): self.assertTrue(obj.run({'thing': 0})) self.assertFalse(obj.run({})) - @raises(koji.GenericError) def test_invalid_compare_test(self): - koji.policy.CompareTest('some thing LOL 2') + with pytest.raises(koji.GenericError): + koji.policy.CompareTest('some thing LOL 2') class TestDiscovery(unittest.TestCase): diff --git a/tests/test_lib/test_tasks.py b/tests/test_lib/test_tasks.py index 858c286..b668352 100644 --- a/tests/test_lib/test_tasks.py +++ b/tests/test_lib/test_tasks.py @@ -53,6 +53,7 @@ def get_tmp_dir_path(folder_starts_with): class TestTask(BaseTaskHandler): + __test__ = False Methods = ['some_method'] _taskWeight = 5.2 @@ -61,6 +62,7 @@ class TestTask(BaseTaskHandler): class TestTaskNoWeight(BaseTaskHandler): + __test__ = False Methods = ['some_method'] def handler(self, *args): diff --git a/tests/test_plugins/test_runroot_cli.py b/tests/test_plugins/test_runroot_cli.py index 17bb6df..6c75f14 100644 --- a/tests/test_plugins/test_runroot_cli.py +++ b/tests/test_plugins/test_runroot_cli.py @@ -83,7 +83,7 @@ class TestListCommands(unittest.TestCase): # Run it and check immediate output runroot.handle_runroot(self.options, self.session, self.args) actual = get_stdout_value(stdout) - actual = actual.replace(b'nosetests', b'koji') + actual = actual.replace(b'pytest', b'koji') expected = b'1\ntask output' self.assertEqual(actual, expected) diff --git a/tox.ini b/tox.ini index 25039a8..ca24388 100644 --- a/tox.ini +++ b/tox.ini @@ -39,7 +39,7 @@ commands_pre = {[testenv]commands_pre} {envbindir}/coverage3 erase --rcfile .coveragerc3 commands = - {envbindir}/coverage3 run --rcfile .coveragerc3 --source . -m nose {posargs} + {envbindir}/coverage3 run --rcfile .coveragerc3 --source . -m pytest {posargs} {envbindir}/coverage3 report --rcfile .coveragerc3 {envbindir}/coverage3 html -d {toxinidir}/htmlcov/py3 --rcfile .coveragerc3 @@ -52,7 +52,7 @@ commands_pre = {[testenv]commands_pre} {envbindir}/coverage2 erase commands = - {envbindir}/coverage2 run --source . -m nose {posargs:\ + {envbindir}/coverage2 run --source . -m pytest {posargs:\ tests/test_builder tests/test_cli \ tests/test_plugins/test_runroot_builder.py \ tests/test_plugins/test_save_failed_tree_builder.py \