[Pytest-commit] commit/pytest: 3 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Oct 11 09:34:35 CEST 2013


3 new commits in pytest:

https://bitbucket.org/hpk42/pytest/commits/24cadf785ead/
Changeset:   24cadf785ead
User:        hpk42
Date:        2013-10-09 22:55:20
Summary:     make "--runxfail" turn imperative pytest.xfail calls into no ops
(it already did neutralize pytest.mark.xfail markers)
Affected #:  4 files

diff -r abb2eaf10864ef237380150cb61dace37dad2ad7 -r 24cadf785eadf26d6533479c676467b0a102b3ac CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -4,6 +4,9 @@
 - In assertion rewriting mode on Python 2, fix the detection of coding
   cookies. See issue #330.
 
+- make "--runxfail" turn imperative pytest.xfail calls into no ops
+  (it already did neutralize pytest.mark.xfail markers)
+
 Changes between 2.4.1 and 2.4.2
 -----------------------------------
 

diff -r abb2eaf10864ef237380150cb61dace37dad2ad7 -r 24cadf785eadf26d6533479c676467b0a102b3ac _pytest/skipping.py
--- a/_pytest/skipping.py
+++ b/_pytest/skipping.py
@@ -10,6 +10,14 @@
            help="run tests even if they are marked xfail")
 
 def pytest_configure(config):
+    if config.option.runxfail:
+        old = pytest.xfail
+        config._cleanup.append(lambda: setattr(pytest, "xfail", old))
+        def nop(*args, **kwargs):
+            pass
+        nop.Exception = XFailed
+        setattr(pytest, "xfail", nop)
+
     config.addinivalue_line("markers",
         "skipif(condition): skip the given test function if eval(condition) "
         "results in a True value.  Evaluation happens within the "

diff -r abb2eaf10864ef237380150cb61dace37dad2ad7 -r 24cadf785eadf26d6533479c676467b0a102b3ac setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,20 @@
 import os, sys
 from setuptools import setup, Command
 
+classifiers=['Development Status :: 6 - Mature',
+             'Intended Audience :: Developers',
+             'License :: OSI Approved :: MIT License',
+             'Operating System :: POSIX',
+             'Operating System :: Microsoft :: Windows',
+             'Operating System :: MacOS :: MacOS X',
+             'Topic :: Software Development :: Testing',
+             'Topic :: Software Development :: Libraries',
+             'Topic :: Utilities',
+             'Programming Language :: Python :: 2',
+             'Programming Language :: Python :: 3'] + [
+            ("Programming Language :: Python :: %s" % x) for x in
+                "2.4 2.5 2.6 2.7 3.0 3.1 3.2 3.3".split()]
+
 long_description = open("README.rst").read()
 def main():
     install_requires = ["py>=1.4.17"]
@@ -20,22 +34,10 @@
         author='Holger Krekel, Benjamin Peterson, Ronny Pfannschmidt, Floris Bruynooghe and others',
         author_email='holger at merlinux.eu',
         entry_points= make_entry_points(),
+        classifiers=classifiers,
         cmdclass = {'test': PyTest},
         # the following should be enabled for release
         install_requires=install_requires,
-        classifiers=['Development Status :: 6 - Mature',
-                     'Intended Audience :: Developers',
-                     'License :: OSI Approved :: MIT License',
-                     'Operating System :: POSIX',
-                     'Operating System :: Microsoft :: Windows',
-                     'Operating System :: MacOS :: MacOS X',
-                     'Topic :: Software Development :: Testing',
-                     'Topic :: Software Development :: Libraries',
-                     'Topic :: Utilities',
-                     'Programming Language :: Python :: 2',
-                     'Programming Language :: Python :: 3'] + [
-        ("Programming Language :: Python :: %s" % x) for x in
-            "2.4 2.5 2.6 2.7 3.0 3.1 3.2 3.3".split()],
         packages=['_pytest', '_pytest.assertion'],
         py_modules=['pytest'],
         zip_safe=False,

diff -r abb2eaf10864ef237380150cb61dace37dad2ad7 -r 24cadf785eadf26d6533479c676467b0a102b3ac testing/test_skipping.py
--- a/testing/test_skipping.py
+++ b/testing/test_skipping.py
@@ -159,13 +159,14 @@
             @pytest.mark.xfail
             def test_func():
                 assert 0
+            def test_func2():
+                pytest.xfail("hello")
         """)
         result = testdir.runpytest("--runxfail")
-        assert result.ret == 1
         result.stdout.fnmatch_lines([
             "*def test_func():*",
             "*assert 0*",
-            "*1 failed*",
+            "*1 failed*1 pass*",
         ])
 
     def test_xfail_evalfalse_but_fails(self, testdir):
@@ -261,10 +262,7 @@
             "*reason:*hello*",
         ])
         result = testdir.runpytest(p, "--runxfail")
-        result.stdout.fnmatch_lines([
-            "*def test_this():*",
-            "*pytest.xfail*",
-        ])
+        result.stdout.fnmatch_lines("*1 pass*")
 
     def test_xfail_imperative_in_setup_function(self, testdir):
         p = testdir.makepyfile("""
@@ -285,10 +283,10 @@
             "*reason:*hello*",
         ])
         result = testdir.runpytest(p, "--runxfail")
-        result.stdout.fnmatch_lines([
-            "*def setup_function(function):*",
-            "*pytest.xfail*",
-        ])
+        result.stdout.fnmatch_lines("""
+            *def test_this*
+            *1 fail*
+        """)
 
     def xtest_dynamic_xfail_set_during_setup(self, testdir):
         p = testdir.makepyfile("""


https://bitbucket.org/hpk42/pytest/commits/c7856bb810f1/
Changeset:   c7856bb810f1
User:        hpk42
Date:        2013-10-11 09:30:08
Summary:     merge
Affected #:  2 files

diff -r 24cadf785eadf26d6533479c676467b0a102b3ac -r c7856bb810f19c52f48c008811154f9907593427 _pytest/assertion/rewrite.py
--- a/_pytest/assertion/rewrite.py
+++ b/_pytest/assertion/rewrite.py
@@ -41,6 +41,7 @@
     def __init__(self):
         self.session = None
         self.modules = {}
+        self._register_with_pkg_resources()
 
     def set_session(self, session):
         self.fnpats = session.config.getini("python_files")
@@ -169,6 +170,24 @@
         tp = desc[2]
         return tp == imp.PKG_DIRECTORY
 
+    @classmethod
+    def _register_with_pkg_resources(cls):
+        """
+        Ensure package resources can be loaded from this loader. May be called
+        multiple times, as the operation is idempotent.
+        """
+        try:
+            import pkg_resources
+            # access an attribute in case a deferred importer is present
+            pkg_resources.__name__
+        except ImportError:
+            return
+
+        # Since pytest tests are always located in the file system, the
+        #  DefaultProvider is appropriate.
+        pkg_resources.register_loader_type(cls, pkg_resources.DefaultProvider)
+
+
 def _write_pyc(state, co, source_path, pyc):
     # Technically, we don't have to have the same pyc format as
     # (C)Python, since these "pycs" should never be seen by builtin

diff -r 24cadf785eadf26d6533479c676467b0a102b3ac -r c7856bb810f19c52f48c008811154f9907593427 testing/test_assertrewrite.py
--- a/testing/test_assertrewrite.py
+++ b/testing/test_assertrewrite.py
@@ -493,3 +493,35 @@
             raise e
         monkeypatch.setattr(b, "open", open)
         assert not _write_pyc(state, [1], source_path, pycpath)
+
+    def test_resources_provider_for_loader(self, testdir):
+        """
+        Attempts to load resources from a package should succeed normally,
+        even when the AssertionRewriteHook is used to load the modules.
+
+        See #366 for details.
+        """
+        pytest.importorskip("pkg_resources")
+
+        testdir.mkpydir('testpkg')
+        contents = {
+            'testpkg/test_pkg': """
+                import pkg_resources
+
+                import pytest
+                from _pytest.assertion.rewrite import AssertionRewritingHook
+
+                def test_load_resource():
+                    assert isinstance(__loader__, AssertionRewritingHook)
+                    res = pkg_resources.resource_string(__name__, 'resource.txt')
+                    res = res.decode('ascii')
+                    assert res == 'Load me please.'
+                """,
+        }
+        testdir.makepyfile(**contents)
+        testdir.maketxtfile(**{'testpkg/resource': "Load me please."})
+
+        result = testdir.runpytest()
+        result.stdout.fnmatch_lines([
+            '* 1 passed*',
+        ])


https://bitbucket.org/hpk42/pytest/commits/9931e8b59b66/
Changeset:   9931e8b59b66
User:        hpk42
Date:        2013-10-11 09:29:28
Summary:     add changelog entry: refine pytest / pkg_resources interactions: The
AssertionRewritingHook PEP302 compliant loader now registers itself with
setuptools/pkg_resources properly so that the
pkg_resources.resource_stream method works properly.  Fixes issue366.
Thanks for the investigations and full PR to Jason R. Coombs.
Affected #:  1 file

diff -r c7856bb810f19c52f48c008811154f9907593427 -r 9931e8b59b66c7dca504db56a1ed87066383c0fe CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,6 +7,11 @@
 - make "--runxfail" turn imperative pytest.xfail calls into no ops
   (it already did neutralize pytest.mark.xfail markers)
 
+- refine pytest / pkg_resources interactions: The AssertionRewritingHook
+  PEP302 compliant loader now registers itself with setuptools/pkg_resources 
+  properly so that the pkg_resources.resource_stream method works properly.
+  Fixes issue366.  Thanks for the investigations and full PR to Jason R. Coombs.
+
 Changes between 2.4.1 and 2.4.2
 -----------------------------------

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the pytest-commit mailing list