New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unittest2 or import conditionally #241
Comments
bump |
@yarda Does the (current) codebase target any Python 2.6 environments (RHEL 6)? This is an important information that blocks us from submitting a pull request for this. |
@hroncok No, it doesn't. A PR would be appreciated. |
@avylove Do you want to do that? I'm on bad internet connection. If not, I can get back here early next week. |
Something like this should do, however untested (diff generating from master branch tarball): diff --git a/tests/unit/exports/test_controller.py b/tests/unit/exports/test_controller.py
index af2e017..333cff5 100644
--- a/tests/unit/exports/test_controller.py
+++ b/tests/unit/exports/test_controller.py
@@ -1,10 +1,10 @@
-import unittest2
+import unittest
from unittest.mock import Mock
from tuned.exports.controller import ExportsController
import tuned.exports as exports
-class ControllerTestCase(unittest2.TestCase):
+class ControllerTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls._controller = ExportsController()
diff --git a/tests/unit/hardware/test_device_matcher.py b/tests/unit/hardware/test_device_matcher.py
index 1987eb6..d3e879f 100644
--- a/tests/unit/hardware/test_device_matcher.py
+++ b/tests/unit/hardware/test_device_matcher.py
@@ -1,7 +1,7 @@
-import unittest2
+import unittest
from tuned.hardware.device_matcher import DeviceMatcher
-class DeviceMatcherTestCase(unittest2.TestCase):
+class DeviceMatcherTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.matcher = DeviceMatcher()
diff --git a/tests/unit/hardware/test_device_matcher_udev.py b/tests/unit/hardware/test_device_matcher_udev.py
index 8e93428..1903955 100644
--- a/tests/unit/hardware/test_device_matcher_udev.py
+++ b/tests/unit/hardware/test_device_matcher_udev.py
@@ -1,9 +1,9 @@
-import unittest2
+import unittest
import pyudev
from tuned.hardware.device_matcher_udev import DeviceMatcherUdev
-class DeviceMatcherUdevTestCase(unittest2.TestCase):
+class DeviceMatcherUdevTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.udev_context = pyudev.Context()
diff --git a/tests/unit/hardware/test_inventory.py b/tests/unit/hardware/test_inventory.py
index 00f8def..36b4678 100644
--- a/tests/unit/hardware/test_inventory.py
+++ b/tests/unit/hardware/test_inventory.py
@@ -1,4 +1,4 @@
-import unittest2
+import unittest
from unittest.mock import Mock
import pyudev
@@ -6,7 +6,7 @@ from tuned.hardware.inventory import Inventory
subsystem_name = "test subsystem"
-class InventoryTestCase(unittest2.TestCase):
+class InventoryTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls._context = pyudev.Context()
diff --git a/tests/unit/monitors/test_base.py b/tests/unit/monitors/test_base.py
index 2d6e82c..8b45fda 100644
--- a/tests/unit/monitors/test_base.py
+++ b/tests/unit/monitors/test_base.py
@@ -1,4 +1,4 @@
-import unittest2
+import unittest
import tuned.monitors.base
class MockMonitor(tuned.monitors.base.Monitor):
@@ -12,7 +12,7 @@ class MockMonitor(tuned.monitors.base.Monitor):
cls._load.setdefault(device, 0)
cls._load[device] += 1
-class MonitorBaseClassTestCase(unittest2.TestCase):
+class MonitorBaseClassTestCase(unittest.TestCase):
def test_fail_base_class_init(self):
with self.assertRaises(NotImplementedError):
tuned.monitors.base.Monitor()
diff --git a/tests/unit/plugins/test_base.py b/tests/unit/plugins/test_base.py
index b49f98e..fdbf6cf 100644
--- a/tests/unit/plugins/test_base.py
+++ b/tests/unit/plugins/test_base.py
@@ -3,7 +3,7 @@ try:
except ImportError:
from collections import Mapping
import tempfile
-import unittest2
+import unittest
from tuned.monitors.repository import Repository
import tuned.plugins.decorators as decorators
@@ -26,7 +26,7 @@ plugin_instance_factory = plugins.instance.Factory()
storage_provider = storage.PickleProvider()
storage_factory = storage.Factory(storage_provider)
-class PluginBaseTestCase(unittest2.TestCase):
+class PluginBaseTestCase(unittest.TestCase):
def setUp(self):
self._plugin = DummyPlugin(monitors_repository,storage_factory,\
hardware_inventory,device_matcher,device_matcher_udev,\
diff --git a/tests/unit/profiles/test_loader.py b/tests/unit/profiles/test_loader.py
index 1f4ed65..b6ea76e 100644
--- a/tests/unit/profiles/test_loader.py
+++ b/tests/unit/profiles/test_loader.py
@@ -1,4 +1,4 @@
-import unittest2
+import unittest
import tempfile
import shutil
import os
@@ -6,7 +6,7 @@ import os
import tuned.profiles as profiles
from tuned.profiles.exceptions import InvalidProfileException
-class LoaderTestCase(unittest2.TestCase):
+class LoaderTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls._test_dir = tempfile.mkdtemp()
diff --git a/tests/unit/profiles/test_locator.py b/tests/unit/profiles/test_locator.py
index 6ab7c5e..741abdc 100644
--- a/tests/unit/profiles/test_locator.py
+++ b/tests/unit/profiles/test_locator.py
@@ -1,10 +1,10 @@
-import unittest2
+import unittest
import os
import shutil
import tempfile
from tuned.profiles.locator import Locator
-class LocatorTestCase(unittest2.TestCase):
+class LocatorTestCase(unittest.TestCase):
def setUp(self):
self.locator = Locator(self._tmp_load_dirs)
diff --git a/tests/unit/profiles/test_merger.py b/tests/unit/profiles/test_merger.py
index 6023b26..7b91d67 100644
--- a/tests/unit/profiles/test_merger.py
+++ b/tests/unit/profiles/test_merger.py
@@ -1,9 +1,9 @@
-import unittest2
+import unittest
from tuned.profiles.merger import Merger
from tuned.profiles.profile import Profile
from collections import OrderedDict
-class MergerTestCase(unittest2.TestCase):
+class MergerTestCase(unittest.TestCase):
def test_merge_without_replace(self):
merger = Merger()
config1 = OrderedDict([
diff --git a/tests/unit/profiles/test_profile.py b/tests/unit/profiles/test_profile.py
index 8f43e3d..e5c85c9 100644
--- a/tests/unit/profiles/test_profile.py
+++ b/tests/unit/profiles/test_profile.py
@@ -1,4 +1,4 @@
-import unittest2
+import unittest
import tuned.profiles
import collections
@@ -6,7 +6,7 @@ class MockProfile(tuned.profiles.profile.Profile):
def _create_unit(self, name, config):
return (name, config)
-class ProfileTestCase(unittest2.TestCase):
+class ProfileTestCase(unittest.TestCase):
def test_init(self):
MockProfile("test", {})
diff --git a/tests/unit/profiles/test_unit.py b/tests/unit/profiles/test_unit.py
index 34bfd0a..d63ff0c 100644
--- a/tests/unit/profiles/test_unit.py
+++ b/tests/unit/profiles/test_unit.py
@@ -1,7 +1,7 @@
-import unittest2
+import unittest
from tuned.profiles import Unit
-class UnitTestCase(unittest2.TestCase):
+class UnitTestCase(unittest.TestCase):
def test_default_options(self):
unit = Unit("sample", {})
diff --git a/tests/unit/utils/test_commands.py b/tests/unit/utils/test_commands.py
index 0950203..d63556e 100644
--- a/tests/unit/utils/test_commands.py
+++ b/tests/unit/utils/test_commands.py
@@ -1,4 +1,4 @@
-import unittest2
+import unittest
import tempfile
import shutil
import re
@@ -9,7 +9,7 @@ import tuned.consts as consts
from tuned.exceptions import TunedException
import tuned.utils.commands
-class CommandsTestCase(unittest2.TestCase):
+class CommandsTestCase(unittest.TestCase):
def setUp(self):
self._commands = commands()
self._test_dir = tempfile.mkdtemp()
diff --git a/tests/unit/utils/test_global_config.py b/tests/unit/utils/test_global_config.py
index d2a9889..5b93888 100644
--- a/tests/unit/utils/test_global_config.py
+++ b/tests/unit/utils/test_global_config.py
@@ -1,4 +1,4 @@
-import unittest2
+import unittest
import tempfile
import shutil
import os
@@ -6,7 +6,7 @@ import os
import tuned.consts as consts
import tuned.utils.global_config as global_config
-class GlobalConfigTestCase(unittest2.TestCase):
+class GlobalConfigTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.test_dir = tempfile.mkdtemp()
diff --git a/tuned.spec b/tuned.spec
index 618d42d..ba8d5f9 100644
--- a/tuned.spec
+++ b/tuned.spec
@@ -60,7 +60,7 @@ Requires(preun): systemd
Requires(postun): systemd
BuildRequires: %{_py}, %{_py}-devel
# BuildRequires for 'make test'
-BuildRequires: %{_py}-unittest2, %{_py}-configobj, %{_py}-mock
+BuildRequires: %{_py}-configobj
BuildRequires: %{_py}-decorator, %{_py}-pyudev
Requires: %{_py}-decorator, %{_py}-pyudev, %{_py}-configobj
Requires: %{_py}-schedutils, %{_py}-linux-procfs, %{_py}-perf
|
I just started a new job, so a bit swamped. Not sure when I'd get a chance. |
But python2.6 is not the only python version where |
Possibly. I'll get back to this next week incl. testing. |
unittest2 is specifically intended to backport features to 2.6. The readme states
Weird that the Python 3 version disagrees. The features you may find in newer versions that aren't present in 2.7 may be:
I don't think these are present in unittest2 either. |
It doesn't. This is new in 3.2 and 2.7. Those releases were happening around the same time. |
Fixes redhat-performance#241 Fedora is removing the unittest2 package https://bugzilla.redhat.com/show_bug.cgi?id=1794222 tuned is not targeting Python 2.6: redhat-performance#241 (comment) Related, mock was also listed as a requirement in the spec file, but all the imports are from unittest.mock, hence removed.
Fixes redhat-performance#241 Fedora is removing the unittest2 package: https://bugzilla.redhat.com/show_bug.cgi?id=1794222 tuned is not targeting Python 2.6: redhat-performance#241 (comment) One thing not present in Python 2.7 is assertItemsEqual() -- renamed to assertCountEqual(). Related, mock was also listed as a requirement in the spec file, but all the imports are from unittest.mock, hence removed.
I've opened #249 |
OK, that explains it. Thanks! |
Several files currently import
unittest2
. This should only be required for Python 2.6. If you're not supporting Python 2.6 anymore, it can be removed, otherwise it should be conditionally imported.This is currently a blocker for retirement of
unittest2
in Fedora.https://bugzilla.redhat.com/show_bug.cgi?id=1794222
Related,
mock
is also listed as a requirement in the spec file, but all the imports are fromunittest.mock
, which indicates Python 3.3+ If this is the case,mock
should be removed from the spec as well, otherwise, it should be a conditional requires only for Python 2.The text was updated successfully, but these errors were encountered: