Commits

Ronny Pfannschmidt committed 1023b4e

capture tests: move imports and declarations to the top

  • Participants
  • Parent commits f2a5abd

Comments (0)

Files changed (1)

testing/test_capture.py

 
 from _pytest import capture
 from _pytest.capture import CaptureManager
+from py.builtin import print_
 
 needsosdup = pytest.mark.xfail("not hasattr(os, 'dup')")
 
+if sys.version_info >= (3, 0):
+    def tobytes(obj):
+        if isinstance(obj, str):
+            obj = obj.encode('UTF-8')
+        assert isinstance(obj, bytes)
+        return obj
+
+    def totext(obj):
+        if isinstance(obj, bytes):
+            obj = str(obj, 'UTF-8')
+        assert isinstance(obj, str)
+        return obj
+else:
+    def tobytes(obj):
+        if isinstance(obj, unicode):
+            obj = obj.encode('UTF-8')
+        assert isinstance(obj, str)
+        return obj
+
+    def totext(obj):
+        if isinstance(obj, str):
+            obj = unicode(obj, 'UTF-8')
+        assert isinstance(obj, unicode)
+        return obj
+
+
+def oswritebytes(fd, obj):
+    os.write(fd, tobytes(obj))
+
+
 
 class TestCaptureManager:
     def test_getmethod_default_no_fd(self, testdir, monkeypatch):
     ])
 
 
-needsdup = pytest.mark.skipif("not hasattr(os, 'dup')")
-
-from py.builtin import print_
-
-
-if sys.version_info >= (3, 0):
-    def tobytes(obj):
-        if isinstance(obj, str):
-            obj = obj.encode('UTF-8')
-        assert isinstance(obj, bytes)
-        return obj
-
-    def totext(obj):
-        if isinstance(obj, bytes):
-            obj = str(obj, 'UTF-8')
-        assert isinstance(obj, str)
-        return obj
-else:
-    def tobytes(obj):
-        if isinstance(obj, unicode):
-            obj = obj.encode('UTF-8')
-        assert isinstance(obj, str)
-        return obj
-
-    def totext(obj):
-        if isinstance(obj, str):
-            obj = unicode(obj, 'UTF-8')
-        assert isinstance(obj, unicode)
-        return obj
-
-
-def oswritebytes(fd, obj):
-    os.write(fd, tobytes(obj))
-
-
 class TestTextIO:
     def test_text(self):
         f = capture.TextIO()
     return f
 
 
-@needsdup
+@needsosdup
 def test_dupfile(tmpfile):
     flist = []
     for i in range(5):
 
 
 class TestFDCapture:
-    pytestmark = needsdup
+    pytestmark = needsosdup
 
     def test_not_now(self, tmpfile):
         fd = tmpfile.fileno()
 
 
 class TestStdCaptureFD(TestStdCapture):
-    pytestmark = needsdup
+    pytestmark = needsosdup
 
     def getcapture(self, **kw):
         return capture.StdCaptureFD(**kw)
 
 
 class TestStdCaptureFDNotNow(TestStdCaptureFD):
-    pytestmark = needsdup
+    pytestmark = needsosdup
 
     def getcapture(self, **kw):
         kw['now'] = False
         return cap
 
 
-@needsdup
+@needsosdup
 def test_stdcapture_fd_tmpfile(tmpfile):
     capfd = capture.StdCaptureFD(out=tmpfile)
     os.write(1, "hello".encode("ascii"))
 
 
 class TestStdCaptureFDinvalidFD:
-    pytestmark = needsdup
+    pytestmark = needsosdup
 
     def test_stdcapture_fd_invalid_fd(self, testdir):
         testdir.makepyfile("""
     capsys.reset()
 
 
-@needsdup
+@needsosdup
 def test_capture_no_sys():
     capsys = capture.StdCapture()
     try:
         capsys.reset()
 
 
-@needsdup
+@needsosdup
 def test_callcapture_nofd():
     def func(x, y):
         oswritebytes(1, "hello")
     assert err.startswith("4")
 
 
-@needsdup
+@needsosdup
 @pytest.mark.parametrize('use', [True, False])
 def test_fdcapture_tmpfile_remains_the_same(tmpfile, use):
     if not use: