man-group / man-group/pytest-plugins

Remove dependency on the external module mock

Open
#168 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug releasing
Dominant language
Python
Stars
597
Forks
89
PR merge metrics
No merged PRs in 30d

Description

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:
```diff
--- 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']
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/unit/test_venv.py and review its use of the external mock module in the two PYTHONPATH tests. Confirm the standard-library unittest.mock import works with the supported Python version, then run the relevant unit tests; done means the tests pass without importing mock.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Refactor
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.