예제 #1
0
    def test_sys_pycache_prefix_integration(self, tmp_path, monkeypatch,
                                            testdir):
        """Integration test for sys.pycache_prefix (#4730)."""
        pycache_prefix = tmp_path / "my/pycs"
        monkeypatch.setattr(sys, "pycache_prefix", str(pycache_prefix))
        monkeypatch.setattr(sys, "dont_write_bytecode", False)

        testdir.makepyfile(
            **{
                "src/test_foo.py": """
                import bar
                def test_foo():
                    pass
            """,
                "src/bar/__init__.py": "",
            })
        result = testdir.runpytest()
        assert result.ret == 0

        test_foo = Path(testdir.tmpdir) / "src/test_foo.py"
        bar_init = Path(testdir.tmpdir) / "src/bar/__init__.py"
        assert test_foo.is_file()
        assert bar_init.is_file()

        # test file: rewritten, custom pytest cache tag
        test_foo_pyc = get_cache_dir(test_foo) / ("test_foo" + PYC_TAIL)
        assert test_foo_pyc.is_file()

        # normal file: not touched by pytest, normal cache tag
        bar_init_pyc = get_cache_dir(
            bar_init) / "__init__.{cache_tag}.pyc".format(
                cache_tag=sys.implementation.cache_tag)
        assert bar_init_pyc.is_file()
예제 #2
0
    def test_get_cache_dir(self, monkeypatch, prefix, source, expected):
        if prefix:
            if sys.version_info < (3, 8):
                pytest.skip("pycache_prefix not available in py<38")
            monkeypatch.setattr(sys, "pycache_prefix", prefix)

        assert get_cache_dir(Path(source)) == Path(expected)