forked from pool/python-pytest-spec
76 lines
2.0 KiB
Diff
76 lines
2.0 KiB
Diff
|
From 811abee39d7fae705c0b9b2e0598bc0fd4f96c36 Mon Sep 17 00:00:00 2001
|
||
|
From: Steve Kowalik <steven@wedontsleep.org>
|
||
|
Date: Wed, 23 Mar 2022 18:00:06 +1100
|
||
|
Subject: [PATCH] Also support stdlib mock
|
||
|
|
||
|
Python >=3.3 has included mock in the standard library, so try and
|
||
|
import that before falling back to the external mock.
|
||
|
---
|
||
|
pyproject.toml | 2 +-
|
||
|
test/test_patch.py | 5 ++++-
|
||
|
test/test_plugin.py | 5 ++++-
|
||
|
test/test_replacer.py | 5 ++++-
|
||
|
4 files changed, 13 insertions(+), 4 deletions(-)
|
||
|
|
||
|
diff --git a/pyproject.toml b/pyproject.toml
|
||
|
index ca689f9..448d9ad 100644
|
||
|
--- a/pyproject.toml
|
||
|
+++ b/pyproject.toml
|
||
|
@@ -33,7 +33,7 @@ include = ["LICENSE.txt"]
|
||
|
six = "*"
|
||
|
|
||
|
[tool.poetry.dev-dependencies]
|
||
|
-mock = ">1.0.1"
|
||
|
+mock = { version = ">1.0.1", python = "~2.7" }
|
||
|
pytest = "*"
|
||
|
pytest-describe = "*"
|
||
|
pytest-flake8 = "*"
|
||
|
diff --git a/test/test_patch.py b/test/test_patch.py
|
||
|
index 05ec407..bf9fbcf 100644
|
||
|
--- a/test/test_patch.py
|
||
|
+++ b/test/test_patch.py
|
||
|
@@ -4,7 +4,10 @@
|
||
|
"""
|
||
|
import unittest
|
||
|
|
||
|
-from mock import Mock, call
|
||
|
+try:
|
||
|
+ from unittest.mock import Mock, call
|
||
|
+except ImportError:
|
||
|
+ from mock import Mock, call
|
||
|
|
||
|
import pytest_spec
|
||
|
from pytest_spec.patch import pytest_runtest_logstart, pytest_runtest_logreport
|
||
|
diff --git a/test/test_plugin.py b/test/test_plugin.py
|
||
|
index 2bcaec4..ca95800 100755
|
||
|
--- a/test/test_plugin.py
|
||
|
+++ b/test/test_plugin.py
|
||
|
@@ -4,7 +4,10 @@
|
||
|
"""
|
||
|
import unittest
|
||
|
|
||
|
-from mock import Mock, call, patch
|
||
|
+try:
|
||
|
+ from unittest.mock import Mock, call, patch
|
||
|
+except ImportError:
|
||
|
+ from mock import Mock, call, patch
|
||
|
from pytest_spec.plugin import pytest_addoption, pytest_configure
|
||
|
|
||
|
|
||
|
diff --git a/test/test_replacer.py b/test/test_replacer.py
|
||
|
index 9526bc1..a805f83 100644
|
||
|
--- a/test/test_replacer.py
|
||
|
+++ b/test/test_replacer.py
|
||
|
@@ -4,7 +4,10 @@
|
||
|
"""
|
||
|
import unittest
|
||
|
|
||
|
-from mock import patch
|
||
|
+try:
|
||
|
+ from unittest.mock import patch
|
||
|
+except ImportError:
|
||
|
+ from mock import patch
|
||
|
from pytest_spec.replacer import logstart_replacer, report_replacer
|
||
|
|
||
|
|