[py-svn] commit/pytest: 4 new changesets

Bitbucket commits-noreply at bitbucket.org
Tue Nov 20 11:38:17 CET 2012


4 new commits in pytest:


https://bitbucket.org/hpk42/pytest/changeset/6e95f36c5689/
changeset:   6e95f36c5689
user:        hpk42
date:        2012-11-19 14:07:14
summary:     modernize tmpdir fixture (use request.node in tmpdir fixture, use @pytest.fixture)
affected #:  2 files

diff -r eec537f128e1a1e9c80e373051486c290fc24e46 -r 6e95f36c56897a3e93ac4e3d39a97d90db676a0f _pytest/tmpdir.py
--- a/_pytest/tmpdir.py
+++ b/_pytest/tmpdir.py
@@ -54,15 +54,15 @@
     mp.setattr(config, '_tmpdirhandler', t, raising=False)
     mp.setattr(pytest, 'ensuretemp', t.ensuretemp, raising=False)
 
-def pytest_funcarg__tmpdir(request):
+ at pytest.fixture
+def tmpdir(request):
     """return a temporary directory path object
     which is unique to each test function invocation,
     created as a sub directory of the base temporary
     directory.  The returned object is a `py.path.local`_
     path object.
     """
-    name = request._pyfuncitem.name
+    name = request.node.name
     name = py.std.re.sub("[\W]", "_", name)
     x = request.config._tmpdirhandler.mktemp(name, numbered=True)
     return x
-


diff -r eec537f128e1a1e9c80e373051486c290fc24e46 -r 6e95f36c56897a3e93ac4e3d39a97d90db676a0f testing/test_tmpdir.py
--- a/testing/test_tmpdir.py
+++ b/testing/test_tmpdir.py
@@ -1,7 +1,7 @@
 import py, pytest
 import os
 
-from _pytest.tmpdir import pytest_funcarg__tmpdir, TempdirHandler
+from _pytest.tmpdir import tmpdir, TempdirHandler
 
 def test_funcarg(testdir):
     testdir.makepyfile("""
@@ -16,12 +16,12 @@
     # pytest_unconfigure has deleted the TempdirHandler already
     config = item.config
     config._tmpdirhandler = TempdirHandler(config)
-    p = pytest_funcarg__tmpdir(item)
+    p = tmpdir(item._request)
     assert p.check()
     bn = p.basename.strip("0123456789")
     assert bn.endswith("test_func_a_")
     item.name = "qwe/\\abc"
-    p = pytest_funcarg__tmpdir(item)
+    p = tmpdir(item._request)
     assert p.check()
     bn = p.basename.strip("0123456789")
     assert bn == "qwe__abc"



https://bitbucket.org/hpk42/pytest/changeset/992d5d6b38e1/
changeset:   992d5d6b38e1
user:        hpk42
date:        2012-11-19 22:17:55
summary:     fix autouse invocation (off-by-one error), relates to issue in moinmoin test suite
affected #:  5 files

diff -r 6e95f36c56897a3e93ac4e3d39a97d90db676a0f -r 992d5d6b38e127cde032300b02383a88ac1e83b7 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,8 @@
   with autouse fixtures.  If you need generative tests, use
   @pytest.mark.parametrize or pytest_generate_tests, see the
   many examples at http://pytest.org/latest/example/parametrize.html
+- fix autouse-issue where autouse-fixtures would not be discovered
+  if defined in a a/conftest.py file and tests in a/tests/test_some.py
 - fix issue226 - LIFO ordering for fixture teardowns
 - fix issue224 - invocations with >256 char arguments now work
 - fix issue91 - add/discuss package/directory level setups in example


diff -r 6e95f36c56897a3e93ac4e3d39a97d90db676a0f -r 992d5d6b38e127cde032300b02383a88ac1e83b7 _pytest/__init__.py
--- a/_pytest/__init__.py
+++ b/_pytest/__init__.py
@@ -1,2 +1,2 @@
 #
-__version__ = '2.3.4.dev5'
+__version__ = '2.3.4.dev6'


diff -r 6e95f36c56897a3e93ac4e3d39a97d90db676a0f -r 992d5d6b38e127cde032300b02383a88ac1e83b7 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -1455,7 +1455,7 @@
         for baseid, basenames in self._nodeid_and_autousenames:
             if nodeid.startswith(baseid):
                 if baseid:
-                    i = len(baseid) + 1
+                    i = len(baseid)
                     nextchar = nodeid[i:i+1]
                     if nextchar and nextchar not in ":/":
                         continue


diff -r 6e95f36c56897a3e93ac4e3d39a97d90db676a0f -r 992d5d6b38e127cde032300b02383a88ac1e83b7 setup.py
--- a/setup.py
+++ b/setup.py
@@ -48,7 +48,7 @@
         name='pytest',
         description='py.test: simple powerful testing with Python',
         long_description = long_description,
-        version='2.3.4.dev5',
+        version='2.3.4.dev6',
         url='http://pytest.org',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],


diff -r 6e95f36c56897a3e93ac4e3d39a97d90db676a0f -r 992d5d6b38e127cde032300b02383a88ac1e83b7 testing/python/fixture.py
--- a/testing/python/fixture.py
+++ b/testing/python/fixture.py
@@ -948,7 +948,26 @@
         reprec = testdir.inline_run()
         reprec.assertoutcome(passed=3)
 
+
 class TestAutouseManagement:
+    def test_autouse_conftest_mid_directory(self, testdir):
+        pkgdir = testdir.mkpydir("xyz123")
+        pkgdir.join("conftest.py").write(py.code.Source("""
+            import pytest
+            @pytest.fixture(autouse=True)
+            def app():
+                import sys
+                sys._myapp = "hello"
+        """))
+        t = pkgdir.ensure("tests", "test_app.py")
+        t.write(py.code.Source("""
+            import sys
+            def test_app():
+                assert sys._myapp == "hello"
+        """))
+        reprec = testdir.inline_run("-s")
+        reprec.assertoutcome(passed=1)
+
     def test_funcarg_and_setup(self, testdir):
         testdir.makepyfile("""
             import pytest



https://bitbucket.org/hpk42/pytest/changeset/a4ce00a86c9d/
changeset:   a4ce00a86c9d
user:        hpk42
date:        2012-11-19 22:17:59
summary:     make yielded tests participate in the autouse protocol
affected #:  3 files

diff -r 992d5d6b38e127cde032300b02383a88ac1e83b7 -r a4ce00a86c9daabc16ee91c306e3baf892e8b759 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 Changes between 2.3.3 and 2.3.4.dev
 -----------------------------------
 
+- yielded tests will activate autouse-fixtures
 - NOTE: the pre-2.0 way of yielding tests is not compatible
   with autouse fixtures.  If you need generative tests, use
   @pytest.mark.parametrize or pytest_generate_tests, see the


diff -r 992d5d6b38e127cde032300b02383a88ac1e83b7 -r a4ce00a86c9daabc16ee91c306e3baf892e8b759 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -528,7 +528,7 @@
 
 def fillfixtures(function):
     """ fill missing funcargs for a test function. """
-    if getattr(function, "_args", None) is None:  # not a yielded function
+    if 1 or getattr(function, "_args", None) is None:  # not a yielded function
         try:
             request = function._request
         except AttributeError:
@@ -906,12 +906,15 @@
                 self.keywords[name] = val
 
         fm = self.session._fixturemanager
-        self._fixtureinfo = fi = fm.getfixtureinfo(self.parent,
-                                                   self.obj, self.cls)
+        isyield = self._isyieldedfunction()
+        self._fixtureinfo = fi = fm.getfixtureinfo(self.parent, self.obj,
+                                                   self.cls,
+                                                   funcargs=not isyield)
         self.fixturenames = fi.names_closure
-        if self._isyieldedfunction():
+        if isyield:
             assert not callspec, (
                 "yielded functions (deprecated) cannot have funcargs")
+            self.funcargs = {}
         else:
             if callspec is not None:
                 self.callspec = callspec
@@ -921,8 +924,7 @@
                     self.param = callspec.param
             else:
                 self.funcargs = {}
-            self._request = req = FixtureRequest(self)
-            #req._discoverfactories()
+        self._request = req = FixtureRequest(self)
 
     @property
     def function(self):
@@ -1398,13 +1400,13 @@
 
         self._nodename2fixtureinfo = {}
 
-    def getfixtureinfo(self, node, func, cls):
+    def getfixtureinfo(self, node, func, cls, funcargs=True):
         key = (node, func.__name__)
         try:
             return self._nodename2fixtureinfo[key]
         except KeyError:
             pass
-        if not hasattr(node, "nofuncargs"):
+        if funcargs and not hasattr(node, "nofuncargs"):
             if cls is not None:
                 startindex = 1
             else:


diff -r 992d5d6b38e127cde032300b02383a88ac1e83b7 -r a4ce00a86c9daabc16ee91c306e3baf892e8b759 testing/python/fixture.py
--- a/testing/python/fixture.py
+++ b/testing/python/fixture.py
@@ -968,6 +968,24 @@
         reprec = testdir.inline_run("-s")
         reprec.assertoutcome(passed=1)
 
+    def test_autouse_honored_for_yield(self, testdir):
+        testdir.makepyfile("""
+            import pytest
+            @pytest.fixture(autouse=True)
+            def tst():
+                global x
+                x = 3
+            def test_gen():
+                def f(hello):
+                    assert x == abs(hello)
+                yield f, 3
+                yield f, -3
+        """)
+        reprec = testdir.inline_run()
+        reprec.assertoutcome(passed=2)
+
+
+
     def test_funcarg_and_setup(self, testdir):
         testdir.makepyfile("""
             import pytest



https://bitbucket.org/hpk42/pytest/changeset/7433673d86bb/
changeset:   7433673d86bb
user:        hpk42
date:        2012-11-19 22:20:37
summary:     adapt changelog entry about autouse fixtures and yield
affected #:  1 file

diff -r a4ce00a86c9daabc16ee91c306e3baf892e8b759 -r 7433673d86bb5a96cb5d6aa6f109ba03a868bb9f CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,10 +2,9 @@
 -----------------------------------
 
 - yielded tests will activate autouse-fixtures
-- NOTE: the pre-2.0 way of yielding tests is not compatible
-  with autouse fixtures.  If you need generative tests, use
-  @pytest.mark.parametrize or pytest_generate_tests, see the
-  many examples at http://pytest.org/latest/example/parametrize.html
+- NOTE: yielded tests cannot use fixtures - if you need this
+  you may want to use the post-2.0 parametrize features, see
+  http://pytest.org/latest/example/parametrize.html
 - fix autouse-issue where autouse-fixtures would not be discovered
   if defined in a a/conftest.py file and tests in a/tests/test_some.py
 - fix issue226 - LIFO ordering for fixture teardowns

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