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

Fixup mock in test_executable_missing_post_creation to work with "ven… #448

Merged
merged 1 commit into from Mar 18, 2022

Conversation

hroncok
Copy link
Contributor

@hroncok hroncok commented Mar 18, 2022

…v" scheme

After #434 the test would error:

____________________ test_executable_missing_post_creation _____________________

mocker = <pytest_mock.plugin.MockerFixture object at 0x7f9a75401a80>

    @pytest.mark.skipif(IS_PYPY3, reason='PyPy3 uses get path to create and provision venv')
    def test_executable_missing_post_creation(mocker):
        mocker.patch.object(build.env, '_should_use_virtualenv', lambda: False)
        original_get_paths = sysconfig.get_paths

        def _get_paths(vars):  # noqa
            shutil.rmtree(vars['base'])
            return original_get_paths(vars=vars)

        get_paths = mocker.patch('sysconfig.get_paths', side_effect=_get_paths)
        with pytest.raises(RuntimeError, match='Virtual environment creation failed, executable .* missing'):
>           with build.env.IsolatedEnvBuilder():

tests/test_env.py:73:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.../site-packages/build/env.py:104: in __enter__
    executable, scripts_dir = _create_isolated_env_venv(self._path)
.../site-packages/build/env.py:258: in _create_isolated_env_venv
    executable, script_dir, purelib = _find_executable_and_scripts(path)
.../site-packages/build/env.py:298: in _find_executable_and_scripts
    paths = sysconfig.get_paths(scheme='venv', vars=config_vars)
/usr/lib64/python3.10/unittest/mock.py:1104: in __call__
    return self._mock_call(*args, **kwargs)
/usr/lib64/python3.10/unittest/mock.py:1108: in _mock_call
    return self._execute_mock_call(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <MagicMock name='get_paths' id='140301368829136'>, args = ()
kwargs = {'scheme': 'venv', 'vars': {'ABIFLAGS': '', 'AC_APPLE_UNIVERSAL_BUILD': 0, 'AIX_BUILDDATE': 0, 'AIX_GENUINE_CPLUSPLUS': 0, ...}}
effect = <function test_executable_missing_post_creation.<locals>._get_paths at 0x7f9a754ac5e0>

    def _execute_mock_call(self, /, *args, **kwargs):
        # separate from _increment_mock_call so that awaited functions are
        # executed separately from their call, also AsyncMock overrides this method

        effect = self.side_effect
        if effect is not None:
            if _is_exception(effect):
                raise effect
            elif not _callable(effect):
                result = next(effect)
                if _is_exception(result):
                    raise result
            else:
>               result = effect(*args, **kwargs)
E               TypeError: test_executable_missing_post_creation.<locals>._get_paths() got an unexpected keyword argument 'scheme'

/usr/lib64/python3.10/unittest/mock.py:1169: TypeError

That only happens when not installed in a virtual environment,
so it was not discovered on CI or via tox.

Copy link
Member

@FFY00 FFY00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I have one nitpick.

tests/test_env.py Outdated Show resolved Hide resolved
…v" scheme

After pypa#434 the test would error:

    ____________________ test_executable_missing_post_creation _____________________

    mocker = <pytest_mock.plugin.MockerFixture object at 0x7f9a75401a80>

        @pytest.mark.skipif(IS_PYPY3, reason='PyPy3 uses get path to create and provision venv')
        def test_executable_missing_post_creation(mocker):
            mocker.patch.object(build.env, '_should_use_virtualenv', lambda: False)
            original_get_paths = sysconfig.get_paths

            def _get_paths(vars):  # noqa
                shutil.rmtree(vars['base'])
                return original_get_paths(vars=vars)

            get_paths = mocker.patch('sysconfig.get_paths', side_effect=_get_paths)
            with pytest.raises(RuntimeError, match='Virtual environment creation failed, executable .* missing'):
    >           with build.env.IsolatedEnvBuilder():

    tests/test_env.py:73:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    .../site-packages/build/env.py:104: in __enter__
        executable, scripts_dir = _create_isolated_env_venv(self._path)
    .../site-packages/build/env.py:258: in _create_isolated_env_venv
        executable, script_dir, purelib = _find_executable_and_scripts(path)
    .../site-packages/build/env.py:298: in _find_executable_and_scripts
        paths = sysconfig.get_paths(scheme='venv', vars=config_vars)
    /usr/lib64/python3.10/unittest/mock.py:1104: in __call__
        return self._mock_call(*args, **kwargs)
    /usr/lib64/python3.10/unittest/mock.py:1108: in _mock_call
        return self._execute_mock_call(*args, **kwargs)
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    self = <MagicMock name='get_paths' id='140301368829136'>, args = ()
    kwargs = {'scheme': 'venv', 'vars': {'ABIFLAGS': '', 'AC_APPLE_UNIVERSAL_BUILD': 0, 'AIX_BUILDDATE': 0, 'AIX_GENUINE_CPLUSPLUS': 0, ...}}
    effect = <function test_executable_missing_post_creation.<locals>._get_paths at 0x7f9a754ac5e0>

        def _execute_mock_call(self, /, *args, **kwargs):
            # separate from _increment_mock_call so that awaited functions are
            # executed separately from their call, also AsyncMock overrides this method

            effect = self.side_effect
            if effect is not None:
                if _is_exception(effect):
                    raise effect
                elif not _callable(effect):
                    result = next(effect)
                    if _is_exception(result):
                        raise result
                else:
    >               result = effect(*args, **kwargs)
    E               TypeError: test_executable_missing_post_creation.<locals>._get_paths() got an unexpected keyword argument 'scheme'

    /usr/lib64/python3.10/unittest/mock.py:1169: TypeError

That only happens when not installed in a virtual environment,
so it was not discovered on CI or via tox.
@FFY00
Copy link
Member

FFY00 commented Mar 18, 2022

Thanks!

@FFY00 FFY00 enabled auto-merge (rebase) March 18, 2022 19:42
@FFY00 FFY00 merged commit 038f0ae into pypa:main Mar 18, 2022
@hroncok hroncok deleted the tests_fixup branch March 18, 2022 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants