Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pytester.syspathinsert() has no effect when using runpytest_subprocess() #10651

Open
plannigan opened this issue Jan 11, 2023 · 1 comment · May be fixed by #12812
Open

Pytester.syspathinsert() has no effect when using runpytest_subprocess() #10651

plannigan opened this issue Jan 11, 2023 · 1 comment · May be fixed by #12812
Labels
plugin: pytester related to the pytester builtin plugin type: bug problem that needs to be addressed

Comments

@plannigan
Copy link
Contributor

Pytester.syspathinsert() uses monkeypatch to temporarily update sys.path for the length of the test. However, runpytest_subprocess() starts a new process to without any knowledge of requested changes to sys.path.

Using pytest 7.2.0, the first test case will pass, but the second will fail.

from pytest import Pytester

SOME_DIR = "foobar"


def test_syspathinsert__in_process__path_exists(pytester: Pytester):
    pytester.syspathinsert(SOME_DIR)
    pytester.makepyfile(
        f"""
        import sys

        def test_foo():
            assert "{SOME_DIR}" in sys.path
        """
    )

    result = pytester.runpytest_inprocess()

    result.assert_outcomes(passed=1)


def test_syspathinsert__sub_process__path_exists(pytester: Pytester):
    pytester.syspathinsert(SOME_DIR)
    pytester.makepyfile(
        f"""
        import sys

        def test_foo():
            assert "{SOME_DIR}" in sys.path
        """
    )

    result = pytester.runpytest_subprocess(timeout=1)

    result.assert_outcomes(passed=1)
@Zac-HD Zac-HD added type: bug problem that needs to be addressed plugin: pytester related to the pytester builtin plugin labels Jan 17, 2023
@Oreldm
Copy link

Oreldm commented Sep 13, 2024

Created a PR : #12812

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: pytester related to the pytester builtin plugin type: bug problem that needs to be addressed
Projects
None yet
3 participants