fix issue185 monkeypatching time.time does not cause pytest to fail
This commit is contained in:
parent
93eac240a0
commit
41ad7dbae1
|
@ -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
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#
|
||||
__version__ = '2.3.0.dev10'
|
||||
__version__ = '2.3.0.dev11'
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
2
setup.py
2
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'],
|
||||
|
|
|
@ -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*
|
||||
""")
|
||||
|
|
Loading…
Reference in New Issue