Commits

Ronny Pfannschmidt  committed 5310b27

clean up expect collectors

  • Participants
  • Parent commits 7c8d34c
  • Branches pytest

Comments (0)

Files changed (1)

File pypy/tool/pytest/expecttest.py

 
 
 import py
-import os, sys
+import pytest
+import os
+import sys
 from pypy.tool.udir import udir
 from pypy.tool.autopath import pypydir
 
 
-class ExpectTestMethod(py.test.collect.Function):
+class ExpectTestMethod(pytest.collect.Function):
     @staticmethod
     def safe_name(target):
         s = "_".join(target)
         s = s.replace(os.sep, "_")
         return s
 
+    #XXX: we really want to get the tmpdir fixture and
+    #     make a expect.py there
     def safe_filename(self):
         name = self.safe_name(self.listnames())
         num = 0
 
     def runtest(self):
         target = self.obj
-        import pexpect
         source = py.code.Source(target)[1:].deindent()
         filename = self.safe_filename()
-        source.lines = ['import sys',
-                      'sys.path.insert(0, %s)' % repr(os.path.dirname(pypydir))
-                        ] + source.lines
+        source.lines = [
+            'import sys',
+            'sys.path.insert(0, %s)' % repr(os.path.dirname(pypydir))
+        ] + source.lines
         source.lines.append('print "%s ok!"' % filename)
         f = udir.join(filename)
         f.write(source)
         child.expect(re.escape(filename + " ok!"))
 
 
-class ExpectClassInstance(py.test.collect.Instance):
+class ExpectClassInstance(pytest.collect.Instance):
     Function = ExpectTestMethod
 
 
-class ExpectClassCollector(py.test.collect.Class):
+class ExpectClassCollector(pytest.collect.Class):
     Instance = ExpectClassInstance
 
     def setup(self):
         super(ExpectClassCollector, self).setup()
-        try:
-            import pexpect
-        except ImportError:
-            py.test.skip("pexpect not found")
-
-
+        pytest.importorskip('pexpect')