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

Remove dependency on the external module mock #168

Open
mcepl opened this issue Dec 11, 2020 · 3 comments
Open

Remove dependency on the external module mock #168

mcepl opened this issue Dec 11, 2020 · 3 comments

Comments

@mcepl
Copy link

mcepl commented Dec 11, 2020

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']
@mcepl
Copy link
Author

mcepl commented Dec 11, 2020

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)

@mcepl
Copy link
Author

mcepl commented Dec 13, 2020

Updated patches:

@eeaston
Copy link
Collaborator

eeaston commented Nov 19, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants