Skip to content

Commit

Permalink
Simulating unittest.mock backport in the Python 2 standard library. (
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Jan 12, 2018
1 parent 452bfdb commit 3614a4c
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 13 deletions.
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
flask
mock
mock; python_version < '3'
pytest
pytest-cov
contexter
Expand Down
29 changes: 29 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2018 Jon Wayne Parrott
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""py.test shared testing configuration.
This monkey-patches ``mock`` as ``unittest.mock`` for Python 2.7.
"""

import sys
import unittest

import six


if six.PY2:
import mock # pylint: disable=import-error
unittest.mock = mock
sys.modules['unittest.mock'] = unittest.mock
16 changes: 15 additions & 1 deletion tests/test__parametrize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import mock
# Copyright 2016 Jon Wayne Parrott
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest import mock

from nox import _parametrize

Expand Down
2 changes: 1 addition & 1 deletion tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import os
import sys
from unittest import mock

import mock
import pytest

import nox.command
Expand Down
2 changes: 1 addition & 1 deletion tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import mock
from unittest import mock

from nox import logger

Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

import os
import sys
from unittest import mock

import contexter
import mock
import pkg_resources

import nox
Expand Down
2 changes: 1 addition & 1 deletion tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

import collections
from unittest import mock

import mock
import pytest

import nox
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

import os
from unittest import mock

import mock
import pytest

from nox._testing import Namespace
Expand Down
3 changes: 1 addition & 2 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import io
import json
import os

import mock
from unittest import mock

import nox
from nox import sessions
Expand Down
6 changes: 3 additions & 3 deletions tests/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import os
import platform
from unittest import mock

import mock
import py
import pytest

Expand Down Expand Up @@ -248,7 +248,7 @@ def test__resolved_interpreter_windows_pyexe(sysfind, system, make_one):
assert venv._resolved_interpreter == r'c:\python36\python.exe'
sysfind.assert_any_call('python3.6')
sysfind.assert_any_call('py')
system.assert_called()
system.assert_called_with()


@mock.patch.object(platform, 'system')
Expand All @@ -273,7 +273,7 @@ def test__resolved_interpreter_windows_pyexe_fails(sysfind, system, make_one):
venv._resolved_interpreter
sysfind.assert_any_call('python3.6')
sysfind.assert_any_call('py')
system.assert_called()
system.assert_called_with()


@mock.patch.object(platform, 'system')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import mock
from unittest import mock

from nox import workflow

Expand Down

0 comments on commit 3614a4c

Please sign in to comment.