#3162 switch from nose to pytest
Closed 3 years ago by tkopecek. Opened 3 years ago by ktdreyer.
ktdreyer/koji pytest  into  master

@@ -17,6 +17,7 @@ 

    python3-devel \

    python3-librepo \

    python3-pip \

+   python3-pytest \

    python3-rpm \

    python3-tox \

    redhat-rpm-config \

@@ -15,6 +15,7 @@ 

    openssl-devel \

    python3-devel \

    python3-pip \

+   python3-pytest \

    python3-rpm \

    python3-tox \

    redhat-rpm-config \

@@ -15,6 +15,7 @@ 

    openssl-devel \

    python3-devel \

    python3-pip \

+   python3-pytest \

    python3-rpm \

    python3-tox \

    redhat-rpm-config \

@@ -15,6 +15,7 @@ 

    openssl-devel \

    python3-devel \

    python3-pip \

+   python3-pytest \

    python3-rpm \

    python3-tox \

    redhat-rpm-config \

@@ -15,6 +15,7 @@ 

    openssl-devel \

    python3-devel \

    python3-pip \

+   python3-pytest \

    python3-rpm \

    python3-tox \

    redhat-rpm-config \

@@ -662,7 +662,7 @@ 

   * ``python3-dateutil``

   * ``python3-mock``

   * ``python3-multilib``

-  * ``python3-nose``

+  * ``python3-pytest``

   * ``python3-psycopg2``

   * ``python3-qpid-proton``

   * ``python3-requests``

file modified
+1 -1
@@ -4,4 +4,4 @@ 

  mock<=2.0.0

  requests-mock

  coverage

- nose

+ pytest

@@ -7,7 +7,7 @@ 

  

  import mock

  import six

- from nose.plugins.skip import SkipTest

+ from unittest import SkipTest

  

  try:

      import libcomps

@@ -1,6 +1,5 @@ 

  import copy

  import unittest

- from nose.tools import eq_

  

  import kojihub

  
@@ -16,7 +15,7 @@ 

          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 @@ 

              {'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 @@ 

              {'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 @@ 

              {'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 @@ 

              {'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 @@ 

              {'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 @@ 

              {'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

@@ -1,4 +1,5 @@ 

  import mock

+ import unittest

  

  import koji

  import kojihub
@@ -6,10 +7,7 @@ 

  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',

@@ -84,7 +84,7 @@ 

          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 @@ 

          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 @@ 

  

      @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()

@@ -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 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 @@ 

          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):

@@ -53,6 +53,7 @@ 

  

  

  class TestTask(BaseTaskHandler):

+     __test__ = False

      Methods = ['some_method']

      _taskWeight = 5.2

  
@@ -61,6 +62,7 @@ 

  

  

  class TestTaskNoWeight(BaseTaskHandler):

+     __test__ = False

      Methods = ['some_method']

  

      def handler(self, *args):

@@ -83,7 +83,7 @@ 

          # 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)

  

file modified
+2 -2
@@ -39,7 +39,7 @@ 

      {[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 @@ 

      {[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 \