============================= test session starts =============================platform win32 -- Python 3.5.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0rootdir: C:\Users\MainUser\PycharmProjects\hypothesis_tests, inifile:plugins: hypothesis-3.8.2collected 1 items hyp_tests.py F================================== FAILURES ===================================__________________________________ test_sort __________________________________ @given(st.lists(st.integers()))> def test_sort(xs):hyp_tests.py:8:...xs = [0, 0, 0, 0, 0, 0, ...] @given(st.lists(st.integers())) def test_sort(xs): res = sorted(xs)> assert all(xi <= xj for xi, xj in zip(res, res[1:]))E assert FalseE + where False = all(<generator object test_sort.<locals>.<genexpr> at 0x00000196C78AA410>)hyp_tests.py:10: AssertionError--------------------------------- Hypothesis ----------------------------------Falsifying example: test_sort(xs=[0, 0, 0, 0, 0, 0, 1, 0])========================== 1 failed in 0.52 seconds ===========================import pytestimport hypothesisimport hypothesis.strategies as stfrom hypothesis import given@given(st.lists(st.integers()))def test_sort(xs): res = sorted(xs) assert all(xi <= xj for xi, xj in zip(res, res[1:]))def sorted(xs, f=sorted): return xs if len(xs) == 8 else f(xs)if __name__ == "__main__": pytest.main(__file__)st.just(x) ==> x, x, x, ...st.none() ==> None, None, None, ...st.one_of(a, b, c) ==> a, a, b, c, a, ...st.booleans() ==> True, True, False, ...st.integers() ==> 1, 2, -4, ...st.floats() ==> math.pi, 13.1, 42.2, ...st.text() ==> "test", "something", ...st.binary() ==> b"\xef\xff", ...st.sampled_from(iterable)st.tuples(st.none(), st.floats(), st.just(42))st.lists(st.integers())st.sets(st.floats())st.dictionaries(st.integers(), st.text())import cProfilesource = open("slow.py").read()cProfile.run(source, sort="tottime")source = """def test_me(): s = 0 for i in range(1000000): s += i**2 return stest_me()"""cProfile.run(source, sort="tottime") 4 function calls in 0.531 seconds Ordered by: internal time ncalls tottime percall cumtime percall filename:lineno(function) 1 0.531 0.531 0.531 0.531 <string>:2(test_me) 1 0.000 0.000 0.531 0.531 {built-in method builtins.exec} 1 0.000 0.000 0.531 0.531 <string>:2(<module>) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}cProfile - профилирует вызовы функций, бесполезен при профилировании одной функцииВ IPython
%lprun -f slow_func bench() - bench вызывает slow_funс, которую профилируем построчно