pytest-plugins
pytest-plugins copied to clipboard
Remove dependency on the external module mock
Since Python 3.3 mock is present the Python’s standard library, so it is not necessary to use external module. This patch removes the need of using it:
--- a/tests/unit/test_venv.py
+++ b/tests/unit/test_venv.py
@@ -1,4 +1,4 @@
-import mock
+from unittest.mock import patch
import pytest_virtualenv as venv
from pytest_shutil import env
@@ -6,7 +6,7 @@ from pytest_shutil import env
def test_PYTHONPATH_not_present_in_testing_env_if_set():
with env.set_env('PYTHONPATH', 'fred'):
- with mock.patch.object(venv.Workspace, 'run') as run:
+ with patch.object(venv.Workspace, 'run') as run:
venv.VirtualEnv()
call = run.mock_calls[0]
assert 'PYTHONPATH' not in call[2]['env']
@@ -18,7 +18,7 @@ def test_PYTHONPATH_not_present_in_testi
def test_PYTHONPATH_not_present_in_testing_env_if_unset():
with env.no_env('PYTHONPATH'):
- with mock.patch.object(venv.Workspace, 'run') as run:
+ with patch.object(venv.Workspace, 'run') as run:
venv.VirtualEnv()
call = run.mock_calls[0]
assert 'PYTHONPATH' not in call[2]['env']
And while you are at it, you can remove external dependency on virtualenv
as well:
--- a/pytest_virtualenv.py
+++ b/pytest_virtualenv.py
@@ -21,7 +21,7 @@ class FixtureConfig(Config):
# Default values for system resource locations - patch this to change defaults
# Can be a string or list of them
-DEFAULT_VIRTUALENV_FIXTURE_EXECUTABLE = [sys.executable, '-m', 'virtualenv']
+DEFAULT_VIRTUALENV_FIXTURE_EXECUTABLE = [sys.executable, '-m', 'venv']
CONFIG = FixtureConfig(
virtualenv_executable=os.getenv('VIRTUALENV_FIXTURE_EXECUTABLE', DEFAULT_VIRTUALENV_FIXTURE_EXECUTABLE),
@@ -137,7 +137,6 @@ class VirtualEnv(Workspace):
cmd = [self.virtualenv_cmd]
else:
cmd = list(self.virtualenv_cmd)
- cmd.extend(['-p', python or cmdline.get_real_python_executable()])
cmd.extend(self.args)
cmd.append(str(self.virtualenv))
self.run(cmd)
Hi - thanks for raising, the mock issue is shortly being fixed and will be released soon.
virtualenv
however isn't the same as venv
- it has more features and is more popular I believe.