summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2014-12-02 13:30:20 +0100
committerTomas Babej <tbabej@redhat.com>2014-12-17 15:37:56 +0100
commitbc5b13c3dac8e2b858bd397f91eddf738d13c832 (patch)
treece42ab1d2da7f0d693b803f3ede190ae9c0045a4
parent1e27fcc3b1e0ea36a606e5997da6fab2a0432c2e (diff)
downloadfreeipa-bc5b13c3dac8e2b858bd397f91eddf738d13c832.tar.gz
freeipa-bc5b13c3dac8e2b858bd397f91eddf738d13c832.tar.xz
freeipa-bc5b13c3dac8e2b858bd397f91eddf738d13c832.zip
ipatests: Use pytest-sourceorder
The plugin to run tests within a class in the order they're defined in the source was split into a separate project. Use this project instead of a FreeIPA-specific copy. Reviewed-By: Tomas Babej <tbabej@redhat.com>
-rw-r--r--freeipa.spec.in1
-rw-r--r--ipatests/pytest.ini1
-rw-r--r--ipatests/pytest_plugins/ordering.py88
-rw-r--r--ipatests/test_integration/base.py2
-rw-r--r--ipatests/test_integration/test_ordering.py2
5 files changed, 3 insertions, 91 deletions
diff --git a/freeipa.spec.in b/freeipa.spec.in
index 588871450..ea2f596d3 100644
--- a/freeipa.spec.in
+++ b/freeipa.spec.in
@@ -309,6 +309,7 @@ Requires: python-paste
Requires: python-coverage
Requires: python-polib
Requires: python-pytest-multihost >= 0.4
+Requires: python-pytest-sourceorder
Conflicts: %{alt_name}-tests
Obsoletes: %{alt_name}-tests < %{version}
diff --git a/ipatests/pytest.ini b/ipatests/pytest.ini
index 275593682..a24466a2a 100644
--- a/ipatests/pytest.ini
+++ b/ipatests/pytest.ini
@@ -10,7 +10,6 @@ addopts = --doctest-modules
--junit-prefix ipa
-p ipatests.pytest_plugins.nose_compat
-p ipatests.pytest_plugins.declarative
- -p ipatests.pytest_plugins.ordering
-p ipatests.pytest_plugins.integration
-p ipatests.pytest_plugins.beakerlib
# Ignore files for doc tests.
diff --git a/ipatests/pytest_plugins/ordering.py b/ipatests/pytest_plugins/ordering.py
deleted file mode 100644
index 3af496a88..000000000
--- a/ipatests/pytest_plugins/ordering.py
+++ /dev/null
@@ -1,88 +0,0 @@
-# Authors:
-# Petr Viktorin <pviktori@redhat.com>
-#
-# Copyright (C) 2014 Red Hat
-# see file 'COPYING' for use and warranty information
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-"""Pytest plugin for IPA
-
-Adds support for the @pytest.mark.source_order decorator which,
-when applied to a class, runs the test methods in source order.
-
-See test_ordering for an example.
-"""
-
-import unittest
-
-import pytest
-
-
-def ordered(cls):
- """Decorator that marks a test class as ordered
-
- Methods within the marked class will be executed in definition order
- (or more strictly, in ordered by the line number where they're defined).
-
- Subclasses of unittest.TestCase can not be ordered.
-
- Generator methods will not be ordered by this plugin.
- """
- cls._order_plugin__ordered = True
- assert not isinstance(cls, unittest.TestCase), (
- "A unittest.TestCase may not be ordered.")
- cls = pytest.mark.source_order(cls)
- return cls
-
-
-def decorate_items(items):
- node_indexes = {}
- for index, item in enumerate(items):
- try:
- func = item.function
- except AttributeError:
- yield (index, ), item
- continue
-
- key = (index, )
- for node in reversed(item.listchain()):
- # Find the corresponding class
- if isinstance(node, pytest.Class):
- cls = node.cls
- else:
- continue
- if getattr(cls, '_order_plugin__ordered', False):
- node_index = node_indexes.setdefault(node, index)
- # Find first occurence of the method in class hierarchy
- for i, parent_class in enumerate(reversed(cls.mro())):
- if getattr(parent_class, '_order_plugin__ordered', False):
- method = getattr(parent_class, func.__name__, None)
- if method:
- # Sort methods as tuples (position of the class
- # in the inheritance chain, position of the method
- # within that class)
- key = (node_index, 0,
- i, method.func_code.co_firstlineno, node)
- break
- else:
- # Weird case fallback
- # Method name not in any of the classes in MRO, run it last
- key = node_index, 1, func.func_code.co_firstlineno, node
- break
- yield key, item
-
-
-def pytest_collection_modifyitems(session, config, items):
- items[:] = [item for i, item in sorted(decorate_items(items))]
diff --git a/ipatests/test_integration/base.py b/ipatests/test_integration/base.py
index d291c36c2..ee41b4142 100644
--- a/ipatests/test_integration/base.py
+++ b/ipatests/test_integration/base.py
@@ -23,7 +23,7 @@ import pytest
from ipapython.ipa_log_manager import log_mgr
from ipatests.test_integration import tasks
-from ipatests.pytest_plugins.ordering import ordered
+from pytest_sourceorder import ordered
log = log_mgr.get_logger(__name__)
diff --git a/ipatests/test_integration/test_ordering.py b/ipatests/test_integration/test_ordering.py
index ee224901c..583d87c5e 100644
--- a/ipatests/test_integration/test_ordering.py
+++ b/ipatests/test_integration/test_ordering.py
@@ -25,7 +25,7 @@ in a specific order:
- Within a class, test methods are ordered according to source line
"""
-from ipatests.pytest_plugins.ordering import ordered
+from pytest_sourceorder import ordered
@ordered