diff --git a/CHANGELOG b/CHANGELOG index 629e99199..d1fbaeb6a 100644 --- 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 --git a/_pytest/__init__.py b/_pytest/__init__.py index fba95d1c0..372f46d93 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.3.0.dev10' +__version__ = '2.3.0.dev11' diff --git a/_pytest/runner.py b/_pytest/runner.py index f528236ab..c774835de 100644 --- 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 @@ class CallInfo: #: 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 @@ class CallInfo: except: self.excinfo = py.code.ExceptionInfo() finally: - self.stop = time.time() + self.stop = time() def __repr__(self): if self.excinfo: diff --git a/doc/en/funcargs.txt b/doc/en/funcargs.txt index 575f833b8..e77b69565 100644 --- a/doc/en/funcargs.txt +++ b/doc/en/funcargs.txt @@ -599,6 +599,35 @@ see :ref:`mark`. 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 --git a/setup.py b/setup.py index b7d70161f..bdef93d89 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def main(): 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 --git a/testing/test_monkeypatch.py b/testing/test_monkeypatch.py index 03a6f703b..1fafb73e5 100644 --- a/testing/test_monkeypatch.py +++ b/testing/test_monkeypatch.py @@ -193,3 +193,16 @@ def test_chdir_double_undo(mp, tmpdir): 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* + """)