[Python-modules-commits] [python-flaky] 01/02: Import python-flaky_3.1.0.orig.tar.gz

Tristan Seligmann mithrandi at moszumanska.debian.org
Wed Feb 17 16:08:21 UTC 2016


This is an automated email from the git hooks/post-receive script.

mithrandi pushed a commit to branch jessie-backports
in repository python-flaky.

commit dfbdbed6f8a75856fd713244afcb6097b1e0ad8c
Author: Tristan Seligmann <mithrandi at mithrandi.net>
Date:   Wed Feb 17 18:02:28 2016 +0200

    Import python-flaky_3.1.0.orig.tar.gz
---
 HISTORY.rst                              |  8 +++
 MANIFEST.in                              |  1 +
 flaky/flaky_nose_plugin.py               |  6 +--
 flaky/flaky_pytest_plugin.py             | 92 +++++++++++++++-----------------
 setup.cfg                                |  5 ++
 setup.py                                 | 32 +++++++++--
 test/test_nose/test_flaky_nose_plugin.py |  4 +-
 tox.ini                                  |  1 +
 8 files changed, 93 insertions(+), 56 deletions(-)

diff --git a/HISTORY.rst b/HISTORY.rst
index 9dd074f..f378690 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -6,6 +6,14 @@ Release History
 Upcoming
 ++++++++
 
+3.1.0 (2016-22-11)
+++++++++++++++++++
+
+- Flaky's automated tests now include a run with the ``pytest-xdist`` plugin enabled.
+- Flaky for pytest has slightly changed how it patches the runner. This simplifies the plugin code a bit, but,
+  more importantly, avoids reporting test retries until flaky is done with them. This *should* improve compatibility
+  with other plugins.
+
 3.0.2 (2015-12-21)
 ++++++++++++++++++
 
diff --git a/MANIFEST.in b/MANIFEST.in
index 0c73842..b025141 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1 +1,2 @@
 include README.rst LICENSE
+recursive-include test test*.py __init__.py
diff --git a/flaky/flaky_nose_plugin.py b/flaky/flaky_nose_plugin.py
index 8bb1f73..48789a2 100644
--- a/flaky/flaky_nose_plugin.py
+++ b/flaky/flaky_nose_plugin.py
@@ -150,7 +150,7 @@ class FlakyPlugin(_FlakyPlugin, Plugin):
         want_error = self._handle_test_error_or_failure(test, err)
         if not want_error and id(test) in self._tests_that_reran:
             self._nose_result.addError(test, err)
-        return want_error
+        return want_error or None
 
     def handleFailure(self, test, err):
         """
@@ -176,7 +176,7 @@ class FlakyPlugin(_FlakyPlugin, Plugin):
         want_failure = self._handle_test_error_or_failure(test, err)
         if not want_failure and id(test) in self._tests_that_reran:
             self._nose_result.addFailure(test, err)
-        return want_failure
+        return want_failure or None
 
     def addSuccess(self, test):
         """
@@ -199,7 +199,7 @@ class FlakyPlugin(_FlakyPlugin, Plugin):
             `bool`
         """
         # pylint:disable=invalid-name
-        return self._handle_test_success(test)
+        return self._handle_test_success(test) or None
 
     def report(self, stream):
         """
diff --git a/flaky/flaky_pytest_plugin.py b/flaky/flaky_pytest_plugin.py
index 322b752..0117155 100644
--- a/flaky/flaky_pytest_plugin.py
+++ b/flaky/flaky_pytest_plugin.py
@@ -1,11 +1,8 @@
 # coding: utf-8
 
 from __future__ import unicode_literals
-import pytest
 
-# pylint:disable=import-error
-from _pytest.runner import CallInfo
-# pylint:enable=import-error
+from _pytest.runner import CallInfo  # pylint:disable=import-error
 
 from flaky._flaky_plugin import _FlakyPlugin
 
@@ -75,11 +72,11 @@ class FlakyPlugin(_FlakyPlugin):
                 self.max_runs,
                 self.min_passes,
             )
-        original_call_runtest_hook = self.runner.call_runtest_hook
+        original_call_and_report = self.runner.call_and_report
         self._call_infos[item] = {}
         should_rerun = True
         try:
-            self.runner.call_runtest_hook = self.call_runtest_hook
+            self.runner.call_and_report = self.call_and_report
             while should_rerun:
                 self.runner.pytest_runtest_protocol(item, nextitem)
                 call_info = self._call_infos.get(item, {}).get(self._PYTEST_WHEN_CALL, None)
@@ -93,10 +90,48 @@ class FlakyPlugin(_FlakyPlugin):
                     if not should_rerun:
                         item.excinfo = call_info.excinfo
         finally:
-            self.runner.call_runtest_hook = original_call_runtest_hook
+            self.runner.call_and_report = original_call_and_report
             del self._call_infos[item]
         return True
 
+    def call_and_report(self, item, when, log=True, **kwds):
+        """
+        Monkey patched from the runner plugin. Responsible for running
+        the test and reporting the outcome.
+        Had to be patched to avoid reporting about test retries.
+
+        :param item:
+            py.test wrapper for the test function to be run
+        :type item:
+            :class:`Function`
+        :param when:
+            The stage of the test being run. Usually one of 'setup', 'call', 'teardown'.
+        :type when:
+            `str`
+        :param log:
+            Whether or not to report the test outcome. Ignored for test
+            retries; flaky doesn't report test retries, only the final outcome.
+        :type log:
+            `bool`
+        """
+        call = self.call_runtest_hook(item, when, **kwds)
+        hook = item.ihook
+        report = hook.pytest_runtest_makereport(item=item, call=call)
+        # Start flaky modifications
+        if report.outcome == self._PYTEST_OUTCOME_PASSED:
+            if self._should_handle_test_success(item):
+                log = False
+        elif report.outcome == self._PYTEST_OUTCOME_FAILED:
+            err, name = self._get_test_name_and_err(item)
+            if self._will_handle_test_error_or_failure(item, name, err):
+                log = False
+        # End flaky modifications
+        if log:
+            hook.pytest_runtest_logreport(report=report)
+        if self.runner.check_interactive_exception(call, report):
+            hook.pytest_exception_interact(node=item, call=call, report=report)
+        return report
+
     def _get_test_name_and_err(self, item):
         """
         Get the test name and error tuple from a test item.
@@ -112,51 +147,12 @@ class FlakyPlugin(_FlakyPlugin):
         """
         _, _, name = self._get_test_declaration_callable_and_name(item)
         call_info = self._call_infos.get(item, {}).get(self._PYTEST_WHEN_CALL, None)
-        if call_info is not None:
+        if call_info is not None and call_info.excinfo:
             err = (call_info.excinfo.type, call_info.excinfo.value, call_info.excinfo.tb)
         else:
             err = (None, None, None)
         return err, name
 
-    @pytest.hookimpl(tryfirst=True, hookwrapper=True)
-    def pytest_runtest_makereport(self, item, call):
-        """
-        Pytest hook to intercept the report for reruns.
-
-        Change the report's outcome to 'passed' if flaky is going to handle the test run.
-        That way, pytest will not mark the run as failed.
-        """
-        outcome = yield
-        if call.when == self._PYTEST_WHEN_CALL:
-            report = outcome.get_result()
-            report.item = item
-            report.original_outcome = report.outcome
-            if report.failed:
-                err, name = self._get_test_name_and_err(item)
-                if self._will_handle_test_error_or_failure(item, name, err):
-                    report.outcome = self._PYTEST_OUTCOME_PASSED
-
-    @pytest.hookimpl(tryfirst=True, hookwrapper=True)
-    def pytest_report_teststatus(self, report):
-        """
-        Pytest hook to only add final runs to the report.
-
-        Given a test report, get the correpsonding test status.
-        For tests that flaky is handling, return the empty status
-        so it isn't reported; otherwise, don't change the status.
-        """
-        outcome = yield
-        if report.when == self._PYTEST_WHEN_CALL:
-            item = report.item
-            if report.original_outcome == self._PYTEST_OUTCOME_PASSED:
-                if self._should_handle_test_success(item):
-                    outcome.force_result(self._PYTEST_EMPTY_STATUS)
-            elif report.original_outcome == self._PYTEST_OUTCOME_FAILED:
-                err, name = self._get_test_name_and_err(item)
-                if self._will_handle_test_error_or_failure(item, name, err):
-                    outcome.force_result(self._PYTEST_EMPTY_STATUS)
-            delattr(report, 'item')
-
     def pytest_terminal_summary(self, terminalreporter):
         """
         Pytest hook to write details about flaky tests to the test report.
@@ -202,7 +198,7 @@ class FlakyPlugin(_FlakyPlugin):
         self.min_passes = config.option.min_passes
         self.runner = config.pluginmanager.getplugin("runner")
         if config.pluginmanager.hasplugin('xdist'):
-            config.pluginmanager.register(FlakyXdist(self))
+            config.pluginmanager.register(FlakyXdist(self), name='flaky.xdist')
             self.config = config
         if hasattr(config, 'slaveoutput'):
             config.slaveoutput['flaky_report'] = ''
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..c34b498
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,5 @@
+[bdist_wheel]
+# This flag says that the code is written to work on both Python 2 and Python
+# 3. If at all possible, it is good practice to do this. If you cannot, you
+# will need to generate wheels for each Python version that you support.
+universal=1
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 9a92cce..eb0d409 100644
--- a/setup.py
+++ b/setup.py
@@ -1,8 +1,11 @@
 # -*- coding: utf-8 -*-
 
 from __future__ import unicode_literals
-from setuptools import setup, find_packages
 from os.path import dirname, join
+import sys
+from setuptools.command.test import test as TestCommand
+from setuptools import setup, find_packages
+
 
 CLASSIFIERS = [
     'Development Status :: 4 - Beta',
@@ -24,11 +27,33 @@ CLASSIFIERS = [
 ]
 
 
+class Tox(TestCommand):
+    user_options = [(b'tox-args=', b'a', 'Arguments to pass to tox')]
+
+    def initialize_options(self):
+        TestCommand.initialize_options(self)
+        self.tox_args = None
+
+    def finalize_options(self):
+        TestCommand.finalize_options(self)
+        self.test_args = []
+        self.test_suite = True
+
+    def run_tests(self):
+        import shlex
+        import tox
+        args = self.tox_args
+        if args:
+            args = shlex.split(self.tox_args)
+        errno = tox.cmdline(args=args)
+        sys.exit(errno)
+
+
 def main():
     base_dir = dirname(__file__)
     setup(
         name='flaky',
-        version='3.0.2',
+        version='3.1.0',
         description='Plugin for nose or py.test that automatically reruns flaky tests.',
         long_description=open(join(base_dir, 'README.rst')).read(),
         author='Box',
@@ -37,7 +62,8 @@ def main():
         license=open(join(base_dir, 'LICENSE')).read(),
         packages=find_packages(exclude=['test*']),
         test_suite='test',
-        tests_require=['pytest', 'nose'],
+        tests_require=['tox'],
+        cmdclass={'test': Tox},
         zip_safe=False,
         entry_points={
             'nose.plugins.0.10': [
diff --git a/test/test_nose/test_flaky_nose_plugin.py b/test/test_nose/test_flaky_nose_plugin.py
index f7d496f..8628f68 100644
--- a/test/test_nose/test_flaky_nose_plugin.py
+++ b/test/test_nose/test_flaky_nose_plugin.py
@@ -281,7 +281,7 @@ class TestFlakyNosePlugin(TestCase):
             )
 
         self.assertEqual(
-            expected_plugin_handles_failure,
+            expected_plugin_handles_failure or None,
             actual_plugin_handles_failure,
             'Expected plugin{0} to handle the test run, but it did{1}.'.format(
                 ' to' if expected_plugin_handles_failure else '',
@@ -382,7 +382,7 @@ class TestFlakyNosePlugin(TestCase):
         )
 
         self.assertEqual(
-            expected_plugin_handles_success,
+            expected_plugin_handles_success or None,
             actual_plugin_handles_success,
             'Expected plugin{0} to handle the test run, but it did{1}.'.format(
                 ' not' if expected_plugin_handles_success else '',
diff --git a/tox.ini b/tox.ini
index be11204..6e63066 100644
--- a/tox.ini
+++ b/tox.ini
@@ -17,6 +17,7 @@ usedevelop = True
 commands =
     nosetests --with-flaky --exclude="test_nose_options_example" test/test_nose/
     py.test -k 'example and not options' --doctest-modules test/test_pytest/
+    py.test -k 'example and not options' -n 1 test/test_pytest/
     py.test -p no:flaky test/test_pytest/test_flaky_pytest_plugin.py
     nosetests --with-flaky --force-flaky --max-runs 2 test/test_nose/test_nose_options_example.py
     py.test --force-flaky --max-runs 2  test/test_pytest/test_pytest_options_example.py

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-flaky.git



More information about the Python-modules-commits mailing list