Commits

Brian Kearns  committed fb31f21

make sure test_app_main reverts cwd after using chdir

  • Participants
  • Parent commits aabdafe

Comments (0)

Files changed (1)

File pypy/interpreter/test2/test_app_main.py

     These tests require pexpect (UNIX-only).
     http://pexpect.sourceforge.net/
     """
-    def setup_class(cls):
-        # some tests need to be able to import test2, change the cwd
-        goal_dir = os.path.abspath(os.path.join(os.path.realpath(os.path.dirname(__file__)), '..'))
-        os.chdir(goal_dir)
-
     def _spawn(self, *args, **kwds):
         try:
             import pexpect
         child.expect('789')    # expect to see it before the timeout hits
         child.sendline('X')
 
-    def test_options_i_m(self):
+    def test_options_i_m(self, monkeypatch):
         if sys.platform == "win32":
             skip("close_fds is not supported on Windows platforms")
         if not hasattr(runpy, '_run_module_as_main'):
             skip("requires CPython >= 2.6")
         p = os.path.join(os.path.realpath(os.path.dirname(__file__)), 'mymodule.py')
         p = os.path.abspath(p)
+        monkeypatch.chdir(os.path.dirname(app_main))
         child = self.spawn(['-i',
                             '-m', 'test2.mymodule',
                             'extra'])
         child.sendline('Not at all. They could be carried.')
         child.expect('A five ounce bird could not carry a one pound coconut.')
 
-    def test_no_space_before_argument(self):
+    def test_no_space_before_argument(self, monkeypatch):
         if not hasattr(runpy, '_run_module_as_main'):
             skip("requires CPython >= 2.6")
         child = self.spawn(['-cprint "hel" + "lo"'])
         child.expect('hello')
 
+        monkeypatch.chdir(os.path.dirname(app_main))
         child = self.spawn(['-mtest2.mymodule'])
         child.expect('mymodule running')
 
                         '-c "import sys; print sys.warnoptions"')
         assert "['ignore', 'default', 'once', 'error']" in data
 
-    def test_option_m(self):
+    def test_option_m(self, monkeypatch):
         if not hasattr(runpy, '_run_module_as_main'):
             skip("requires CPython >= 2.6")
         p = os.path.join(os.path.realpath(os.path.dirname(__file__)), 'mymodule.py')
         p = os.path.abspath(p)
+        monkeypatch.chdir(os.path.dirname(app_main))
         data = self.run('-m test2.mymodule extra')
         assert 'mymodule running' in data
         assert 'Name: __main__' in data