Home - Summaries: (main) : (py3.11) : Everything - Nightly builds - Benchmarks - RPython - Builders - About

pypy/interpreter/test/test_app_main.py::TestNonInteractive::()::test_proper_sys_path

self = <pypy.interpreter.test.test_app_main.TestNonInteractive instance at 0x0000000111004120>
tmpdir = local('/private/tmp/buildbot-arm64/pytest/pytest-of-matti/pytest-504/test_proper_sys_path0')

    def test_proper_sys_path(self, tmpdir):
        data = self.run('-c "import _ctypes"', python_flags='-S')
        if data.startswith('Traceback'):
            py.test.skip("'python -S' cannot import extension modules: "
                         "see probably http://bugs.python.org/issue586680")
    
        @contextmanager
        def chdir_and_unset_pythonpath(new_cwd):
            old_cwd = new_cwd.chdir()
            old_pythonpath = os.getenv('PYTHONPATH')
            os.unsetenv('PYTHONPATH')
            try:
                yield
            finally:
                old_cwd.chdir()
                # Can't call putenv with a None argument.
                if old_pythonpath is not None:
                    os.putenv('PYTHONPATH', old_pythonpath)
    
        # if we are running in a virtualenv, messing with site.py will
        # make runpy.py and pkgutil unavailable. They are needed to run
        # app_main. Copy them into the tmpdir
        runpy_dir = os.path.dirname(runpy.__file__)
        import pkgutil
        pkgutil_dir = os.path.dirname(pkgutil.__file__)
        shutil.copy(os.path.join(runpy_dir, 'runpy.py'), str(tmpdir))
        shutil.copy(os.path.join(pkgutil_dir, 'pkgutil.py'), str(tmpdir))
        tmpdir.join('site.py').write('print "SHOULD NOT RUN"')
        runme_py = tmpdir.join('runme.py')
        runme_py.write('print "some text"')
    
        cmdline = str(runme_py)
    
        with chdir_and_unset_pythonpath(tmpdir):
            data = self.run(cmdline, python_flags='-S')
    
>       assert data == "some text\n"
E       assert 'debug: Opera...d encodings\n' == 'some text\n'
E         + some text
E         - debug: OperationError:
E         - debug:  operror-type: ImportError
E         - debug:  operror-value: No module named encodings

interpreter/test/test_app_main.py:887: AssertionError
---------- Captured stdout call ----------
POPEN: /Users/matti/build-worker-arm64/own-macos-arm64/build/virt_test/bin/python -S "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/app_main.py" -S -c "import _ctypes"
POPEN: /Users/matti/build-worker-arm64/own-macos-arm64/build/virt_test/bin/python -S "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/app_main.py" -S /private/tmp/buildbot-arm64/pytest/pytest-of-matti/pytest-504/test_proper_sys_path0/runme.py
builder: own-macos-arm64 build #1205
test: pypy/interpreter/test/test_app_main/py/TestNonInteractive/()/test_proper_sys_path