3 new commits in pytest:
https://bitbucket.org/hpk42/pytest/changeset/15afc660b59c/ changeset: 15afc660b59c user: hpk42 date: 2012-08-26 16:30:01 summary: add talk from brianna and me from 2012 affected #: 1 file diff -r 60f144dcdcf4a488ef1114ead43a7d59df8f4663 -r 15afc660b59c97a2152f1371a1dfbba1464c4cf7 doc/en/talks.txt --- a/doc/en/talks.txt +++ b/doc/en/talks.txt @@ -12,8 +12,12 @@ Basic usage and funcargs: +- `pycon australia 2012 pytest talk from Brianna Laugher + <http://2012.pycon-au.org/schedule/52/view_talk?day=sunday>`_ (`video <http://www.youtube.com/watch?v=DTNejE9EraI>`_, `slides <http://www.slideshare.net/pfctdayelise/funcargs-other-fun-with-pytest>`_, `code <https://gist.github.com/3386951>`_) +- `pycon 2012 US talk video from Holger Krekel <http://www.youtube.com/watch?v=9LVqBQcFmyw>`_ - `pycon 2010 tutorial PDF`_ and `tutorial1 repository`_ + Function arguments: - :ref:`mysetup` https://bitbucket.org/hpk42/pytest/changeset/99d9e72b0732/ changeset: 99d9e72b0732 user: hpk42 date: 2012-09-01 09:59:11 summary: merge affected #: 4 files diff -r 15afc660b59c97a2152f1371a1dfbba1464c4cf7 -r 99d9e72b0732d843b71ee9edec63d450fe27bef3 CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -35,6 +35,8 @@ - fix issue128: show captured output when capsys/capfd are used +- fix issue179: propperly show the dependency chain of factories + - pluginmanager.register(...) now raises ValueError if the plugin has been already registered or the name is taken diff -r 15afc660b59c97a2152f1371a1dfbba1464c4cf7 -r 99d9e72b0732d843b71ee9edec63d450fe27bef3 _pytest/python.py --- a/_pytest/python.py +++ b/_pytest/python.py @@ -781,7 +781,7 @@ # we want to catch a AssertionError # replace our subclass with the builtin one # see https://bitbucket.org/hpk42/pytest/issue/176/pytestraises - from exceptions import AssertionError as ExpectedException + from _pytest.assertion.util import BuiltinAssertionError as ExpectedException if not args: return RaisesContext(ExpectedException) @@ -1211,8 +1211,14 @@ def toterminal(self, tw): tw.line() - for line in self.factblines or []: - tw.line(line) + if self.factblines: + tw.line(' dependency of:') + for factorydef in self.factblines: + tw.line(' %s in %s' % ( + factorydef.argname, + factorydef.baseid, + )) + tw.line() for line in self.deflines: tw.line(" " + line.strip()) for line in self.errorstring.split("\n"): @@ -1308,16 +1314,14 @@ obj = getattr(holderobj, name) if not callable(obj): continue - # to avoid breaking on magic global callables - # we explicitly check if we get a sane code object - # else having mock.call in the globals fails for example - code = py.code.getrawcode(obj) - if not inspect.iscode(code): - continue # resource factories either have a pytest_funcarg__ prefix # or are "funcarg" marked marker = getattr(obj, "_pytestfactory", None) if marker is not None: + if not isinstance(marker, FactoryMarker): + # magic globals with __getattr__ + # give us something thats wrong for that case + continue assert not name.startswith(self._argprefix) argname = name scope = marker.scope diff -r 15afc660b59c97a2152f1371a1dfbba1464c4cf7 -r 99d9e72b0732d843b71ee9edec63d450fe27bef3 testing/test_junitxml.py --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -162,7 +162,7 @@ import pytest @pytest.mark.parametrize('arg1', "<&'", ids="<&'") def test_func(arg1): - print arg1 + print(arg1) assert 0 """) result, dom = runandparse(testdir) diff -r 15afc660b59c97a2152f1371a1dfbba1464c4cf7 -r 99d9e72b0732d843b71ee9edec63d450fe27bef3 testing/test_python.py --- a/testing/test_python.py +++ b/testing/test_python.py @@ -1422,9 +1422,9 @@ def test_raises_flip_builtin_AssertionError(self): # we replace AssertionError on python level # however c code might still raise the builtin one - import exceptions + from _pytest.assertion.util import BuiltinAssertionError pytest.raises(AssertionError,""" - raise exceptions.AssertionError + raise BuiltinAssertionError """) @pytest.mark.skipif('sys.version < "2.5"') @@ -1664,6 +1664,30 @@ "*2 passed*" ]) + def test_factory_uses_unknown_funcarg_as_dependency_error(self, testdir): + testdir.makepyfile(""" + import pytest + + @pytest.factory() + def fail(missing): + return + + @pytest.factory() + def call_fail(fail): + return + + def test_missing(call_fail): + pass + """) + result = testdir.runpytest() + result.stdout.fnmatch_lines([ + "*dependency of:*", + "*call_fail*", + "*def fail(*", + "*LookupError: no factory found for argument 'missing'", + ]) + + class TestResourceIntegrationFunctional: def test_parametrize_with_ids(self, testdir): https://bitbucket.org/hpk42/pytest/changeset/00fb4f72c38a/ changeset: 00fb4f72c38a user: hpk42 date: 2012-09-01 09:58:10 summary: fix issue185 monkeypatching time.time does not cause pytest to fail affected #: 6 files diff -r 99d9e72b0732d843b71ee9edec63d450fe27bef3 -r 00fb4f72c38ac921cd9ea3612f0de15878987536 CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Changes between 2.2.4 and 2.3.0.dev ----------------------------------- +- fix issue185 monkeypatching time.time does not cause pytest to fail - fix issue172 duplicate call of pytest.setup-decoratored setup_module functions - fix junitxml=path construction so that if tests change the diff -r 99d9e72b0732d843b71ee9edec63d450fe27bef3 -r 00fb4f72c38ac921cd9ea3612f0de15878987536 _pytest/__init__.py --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.3.0.dev10' +__version__ = '2.3.0.dev11' diff -r 99d9e72b0732d843b71ee9edec63d450fe27bef3 -r 00fb4f72c38ac921cd9ea3612f0de15878987536 _pytest/runner.py --- a/_pytest/runner.py +++ b/_pytest/runner.py @@ -1,6 +1,7 @@ """ basic collect and runtest protocol implementations """ -import py, sys, time +import py, sys +from time import time from py._code.code import TerminalRepr def pytest_namespace(): @@ -114,7 +115,7 @@ #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when - self.start = time.time() + self.start = time() try: try: self.result = func() @@ -123,7 +124,7 @@ except: self.excinfo = py.code.ExceptionInfo() finally: - self.stop = time.time() + self.stop = time() def __repr__(self): if self.excinfo: diff -r 99d9e72b0732d843b71ee9edec63d450fe27bef3 -r 00fb4f72c38ac921cd9ea3612f0de15878987536 doc/en/funcargs.txt --- a/doc/en/funcargs.txt +++ b/doc/en/funcargs.txt @@ -599,6 +599,35 @@ Basic ``pytest_generate_tests`` example --------------------------------------------- +.. XXX + + > line 598 "Basic ``pytest_generate_tests`` example" - I think this is + > not a very basic example! I think it is copied from parametrize.txt + > page, where it might make more sense. Here is what I would consider a + > basic example. + > + > # code + > def isSquare(n): + > n = n ** 0.5 + > return int(n) == n + > + > # test file + > def pytest_generate_tests(metafunc): + > squares = [1, 4, 9, 16, 25, 36, 49] + > for n in range(1, 50): + > expected = n in squares + > if metafunc.function.__name__ == 'test_isSquare': + > metafunc.addcall(id=n, funcargs=dict(n=n, + > expected=expected)) + > + > + > def test_isSquare(n, expected): + > assert isSquare(n) == expected + + +.. XXX + consider adding more examples, also mixed (factory-parametrized/test-function-parametrized, see mail from Brianna) + The ``pytest_generate_tests`` hook is typically used if you want to go beyond what ``@pytest.mark.parametrize`` offers. For example, let's say we want to execute a test with different computation diff -r 99d9e72b0732d843b71ee9edec63d450fe27bef3 -r 00fb4f72c38ac921cd9ea3612f0de15878987536 setup.py --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.3.0.dev10', + version='2.3.0.dev11', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff -r 99d9e72b0732d843b71ee9edec63d450fe27bef3 -r 00fb4f72c38ac921cd9ea3612f0de15878987536 testing/test_monkeypatch.py --- a/testing/test_monkeypatch.py +++ b/testing/test_monkeypatch.py @@ -193,3 +193,16 @@ tmpdir.chdir() mp.undo() assert os.getcwd() == tmpdir.strpath + +def test_issue185_time_breaks(testdir): + testdir.makepyfile(""" + import time + def test_m(monkeypatch): + def f(): + raise Exception + monkeypatch.setattr(time, "time", f) + """) + result = testdir.runpytest() + result.stdout.fnmatch_lines(""" + *1 passed* + """) 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. _______________________________________________ py-svn mailing list py-svn@codespeak.net http://codespeak.net/mailman/listinfo/py-svn