2 new commits in pytest: https://bitbucket.org/hpk42/pytest/commits/6509bce52d28/ Changeset: 6509bce52d28 User: RonnyPfannschmidt Date: 2013-08-01 22:11:18 Summary: fix issue317: assertion rewriter support for the is_package method Affected #: 3 files
diff -r a5240a6c897a70ff55dc91d05e3f756af2004881 -r 6509bce52d28f04b413a42429d38187602a13ed2 CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,8 @@ for standard datatypes and recognise collections.abc. Thanks to Brianna Laugher and Mathieu Agopian. +- fix issue317: assertion rewriter support for the is_package method + - fix issue335: document py.code.ExceptionInfo() object returned from pytest.raises(), thanks Mathieu Agopian. diff -r a5240a6c897a70ff55dc91d05e3f756af2004881 -r 6509bce52d28f04b413a42429d38187602a13ed2 _pytest/assertion/rewrite.py --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -150,12 +150,25 @@ mod.__file__ = co.co_filename # Normally, this attribute is 3.2+. mod.__cached__ = pyc + mod.__loader__ = self py.builtin.exec_(co, mod.__dict__) except: del sys.modules[name] raise return sys.modules[name] + + + def is_package(self, name): + try: + fd, fn, desc = imp.find_module(name) + except ImportError: + return False + if fd is not None: + fd.close() + tp = desc[2] + return tp == imp.PKG_DIRECTORY + 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 a5240a6c897a70ff55dc91d05e3f756af2004881 -r 6509bce52d28f04b413a42429d38187602a13ed2 testing/test_assertrewrite.py --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -412,6 +412,36 @@ testdir.tmpdir.join("test_newlines.py").write(b, "wb") assert testdir.runpytest().ret == 0 + +class TestAssertionRewriteHookDetails(object): + def test_loader_is_package_false_for_module(self, testdir): + testdir.makepyfile(test_fun=""" + def test_loader(): + assert not __loader__.is_package(__name__) + """) + result = testdir.runpytest() + result.stdout.fnmatch_lines([ + "* 1 passed*", + ]) + + def test_loader_is_package_true_for_package(self, testdir): + testdir.makepyfile(test_fun=""" + def test_loader(): + assert not __loader__.is_package(__name__) + + def test_fun(): + assert __loader__.is_package('fun') + + def test_missing(): + assert not __loader__.is_package('pytest_not_there') + """) + pkg = testdir.mkpydir('fun') + result = testdir.runpytest() + result.stdout.fnmatch_lines([ + '* 3 passed*', + ]) + + @pytest.mark.skipif("sys.version_info[0] >= 3") def test_assume_ascii(self, testdir): content = "u'\xe2\x99\xa5'" https://bitbucket.org/hpk42/pytest/commits/9125613a1821/ Changeset: 9125613a1821 User: RonnyPfannschmidt Date: 2013-08-01 22:55:16 Summary: merge Affected #: 3 files diff -r 6509bce52d28f04b413a42429d38187602a13ed2 -r 9125613a1821649a71162cc7f3635d63d3be3e4b CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ Changes between 2.3.5 and 2.4.DEV ----------------------------------- +- fix issue336: autouse fixture in plugins should work again. + - change to use hyphen-separated long options but keep the old spelling backward compatible. py.test -h will only show the hyphenated version, for example "--collect-only" but "--collectonly" will remain valid as well diff -r 6509bce52d28f04b413a42429d38187602a13ed2 -r 9125613a1821649a71162cc7f3635d63d3be3e4b _pytest/python.py --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1626,18 +1626,18 @@ unittest=unittest) faclist = self._arg2fixturedefs.setdefault(name, []) if not fixturedef.has_location: - # All Nones are at the front so this inserts the - # current fixturedef after the existing fixturedefs - # from external plugins but before the fixturedefs - # provided in conftests. - i = faclist.count(None) + # All fixturedefs with no location are at the front + # so this inserts the current fixturedef after the + # existing fixturedefs from external plugins but + # before the fixturedefs provided in conftests. + i = len([f for f in faclist if not f.has_location]) else: i = len(faclist) # append faclist.insert(i, fixturedef) if marker.autouse: autousenames.append(name) if autousenames: - self._nodeid_and_autousenames.append((nodeid, autousenames)) + self._nodeid_and_autousenames.append((nodeid or '', autousenames)) def getfixturedefs(self, argname, nodeid): try: diff -r 6509bce52d28f04b413a42429d38187602a13ed2 -r 9125613a1821649a71162cc7f3635d63d3be3e4b testing/python/fixture.py --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -173,7 +173,7 @@ result = testdir.runpytest(testfile) result.stdout.fnmatch_lines(["*1 passed*"]) - def test_extend_fixture_conftest_plugin(request, testdir): + def test_extend_fixture_conftest_plugin(self, testdir): testdir.makepyfile(testplugin=""" import pytest @@ -198,6 +198,52 @@ result = testdir.runpytest('-s') assert result.ret == 0 + def test_extend_fixture_plugin_plugin(self, testdir): + # Two plugins should extend each order in loading order + testdir.makepyfile(testplugin0=""" + import pytest + + @pytest.fixture + def foo(): + return 7 + """) + testdir.makepyfile(testplugin1=""" + import pytest + + @pytest.fixture + def foo(foo): + return foo + 7 + """) + testdir.syspathinsert() + testdir.makepyfile(""" + pytest_plugins = ['testplugin0', 'testplugin1'] + + def test_foo(foo): + assert foo == 14 + """) + result = testdir.runpytest() + assert result.ret == 0 + + def test_autouse_fixture_plugin(self, testdir): + # A fixture from a plugin has no baseid set, which screwed up + # the autouse fixture handling. + testdir.makepyfile(testplugin=""" + import pytest + + @pytest.fixture(autouse=True) + def foo(request): + request.function.foo = 7 + """) + testdir.syspathinsert() + testdir.makepyfile(""" + pytest_plugins = 'testplugin' + + def test_foo(request): + assert request.function.foo == 7 + """) + result = testdir.runpytest() + assert result.ret == 0 + def test_funcarg_lookup_error(self, testdir): p = testdir.makepyfile(""" def test_lookup_error(unknown): 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. _______________________________________________ pytest-commit mailing list pytest-commit@python.org http://mail.python.org/mailman/listinfo/pytest-commit