[py-svn] commit/pytest: hpk42: separate out the duration tests

Bitbucket commits-noreply at bitbucket.org
Tue Nov 8 19:12:25 CET 2011


1 new commit in pytest:


https://bitbucket.org/hpk42/pytest/changeset/bc7d4c092207/
changeset:   bc7d4c092207
user:        hpk42
date:        2011-11-08 19:12:16
summary:     separate out the duration tests
affected #:  1 file

diff -r 70a660cea75ed5f9eba64cb8e2901b7bb3402829 -r bc7d4c092207173c09d504200eac61e9809e6d24 testing/acceptance_test.py
--- a/testing/acceptance_test.py
+++ b/testing/acceptance_test.py
@@ -465,8 +465,8 @@
             "*1 failed*",
         ])
 
-def test_duration_test(testdir):
-    testdir.makepyfile("""
+class TestDurations:
+    source = """
         import time
         frag = 0.01
         def test_2():
@@ -475,39 +475,57 @@
             time.sleep(frag)
         def test_3():
             time.sleep(frag*3)
-    """)
-    result = testdir.runpytest("--durations=10")
-    assert result.ret == 0
-    result.stdout.fnmatch_lines([
-        "*durations*",
-        "*call*test_3*",
-        "*call*test_2*",
-        "*call*test_1*",
-    ])
-    assert "remaining in"  not in result.stdout.str()
+    """
 
-    result = testdir.runpytest("--durations=2")
-    assert result.ret == 0
-    result.stdout.fnmatch_lines([
-        "*durations*",
-        "*call*test_3*",
-        "*call*test_2*",
-        "*s*%*remaining in 7 test phases",
-    ])
-    assert "test_1" not in result.stdout.str()
-    result = testdir.runpytest("--durations=0")
-    assert result.ret == 0
-    for x in "123":
-        for y in 'call',: #'setup', 'call', 'teardown':
-            l = []
-            for line in result.stdout.lines:
-                if ("test_%s" % x) in line and y in line:
-                    break
-            else:
-                raise AssertionError("not found %s %s" % (x,y))
+    def test_calls(self, testdir):
+        testdir.makepyfile(self.source)
+        result = testdir.runpytest("--durations=10")
+        assert result.ret == 0
+        result.stdout.fnmatch_lines([
+            "*durations*",
+            "*call*test_3*",
+            "*call*test_2*",
+            "*call*test_1*",
+        ])
+        assert "remaining in"  not in result.stdout.str()
 
-def test_duration_test_with_fixture(testdir):
-    testdir.makepyfile("""
+    def test_calls_show_2(self, testdir):
+        testdir.makepyfile(self.source)
+        result = testdir.runpytest("--durations=2")
+        assert result.ret == 0
+        result.stdout.fnmatch_lines([
+            "*durations*",
+            "*call*test_3*",
+            "*call*test_2*",
+            "*s*%*remaining in 7 test phases",
+        ])
+        assert "test_1" not in result.stdout.str()
+
+    def test_calls_showall(self, testdir):
+        testdir.makepyfile(self.source)
+        result = testdir.runpytest("--durations=0")
+        assert result.ret == 0
+        for x in "123":
+            for y in 'call',: #'setup', 'call', 'teardown':
+                l = []
+                for line in result.stdout.lines:
+                    if ("test_%s" % x) in line and y in line:
+                        break
+                else:
+                    raise AssertionError("not found %s %s" % (x,y))
+
+    def test_with_deselected(self, testdir):
+        testdir.makepyfile(self.source)
+        result = testdir.runpytest("--durations=2", "-k test_1")
+        assert result.ret == 0
+        result.stdout.fnmatch_lines([
+            "*durations*",
+            "*call*test_1*",
+        ])
+
+
+class TestDurationWithFixture:
+    source = """
         import time
         frag = 0.01
         def setup_function(func):
@@ -517,21 +535,17 @@
             time.sleep(frag*2)
         def test_2():
             time.sleep(frag)
-    """)
-    result = testdir.runpytest("--durations=10")
-    assert result.ret == 0
-    result.stdout.fnmatch_lines([
-        "*durations*",
-        "*setup*test_1*",
-        "*setup*test_2*",
-        "*call*test_1*",
-        "*call*test_2*",
-    ])
+    """
+    def test_setup_function(self, testdir):
+        testdir.makepyfile(self.source)
+        result = testdir.runpytest("--durations=10")
+        assert result.ret == 0
 
-    result = testdir.runpytest("--durations=2", "-k test_1")
-    assert result.ret == 0
-    result.stdout.fnmatch_lines([
-        "*durations*",
-        "*call*test_1*",
-    ])
+        result.stdout.fnmatch_lines([
+            "*durations*",
+            "*setup*test_1*",
+            "*setup*test_2*",
+            "*call*test_1*",
+            "*call*test_2*",
+        ])

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.



More information about the pytest-commit mailing list