Skip to content

Commit

Permalink
Fix test_executable_missing_post_creation for Python 3.11, PyPy (#459)
Browse files Browse the repository at this point in the history
* Fix mock in test_executable_missing_post_creation for Python 3.11

As a result of python/cpython#31034,
venv now calls sysconfig.get_paths. This messes up the mock call
count.

The change to using Signature.bind isn't strictly necessary, but fixes
the initial symptom (since venv calls sysconfig.get_paths without
kwargs). This also means we can use sysconfig.get_paths however we want.

* add comment, unskip on pypy3

* mock venv.EnvBuilder.create

* remove unused imports

Authored-by: hauntsaninja <>
  • Loading branch information
hauntsaninja authored Apr 17, 2022
1 parent 06c2ebc commit 94e5838
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import inspect
import logging
import platform
import shutil
import subprocess
import sys
import sysconfig

import pytest

Expand Down Expand Up @@ -58,19 +56,12 @@ def test_can_get_venv_paths_with_conflicting_default_scheme(mocker):
assert get_scheme_names.call_count == 1


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

def _get_paths(*args, **kwargs): # noqa
shutil.rmtree(kwargs['vars']['base'])
return original_get_paths(*args, **kwargs)

get_paths = mocker.patch('sysconfig.get_paths', side_effect=_get_paths)
venv_create = mocker.patch('venv.EnvBuilder.create')
with pytest.raises(RuntimeError, match='Virtual environment creation failed, executable .* missing'):
with build.env.IsolatedEnvBuilder():
pass
assert get_paths.call_count == 1
assert venv_create.call_count == 1


def test_isolated_env_abstract():
Expand Down

0 comments on commit 94e5838

Please sign in to comment.