8000 Prefer unittest.mock but require mock for python < 3.3. · jlitzingerdev/klein@adc6341 · GitHub
[go: up one dir, main page]

Skip to content

Commit adc6341

Browse files
committed
Prefer unittest.mock but require mock for python < 3.3.
The unit tests require mock but don't specify it, which causes problems for any usages outside tox (e.g. testing that changes to twisted don't break klein). Use PEP508 to specify environment markers and only install mock when required. Tests can then conditionally import unittest.mock and fall back to mock. The conditional imports do raise a mypy error, discussed here: python/mypy#1153 So an annotation is required to silence this specific warning.
1 parent 61c0661 commit adc6341

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mock ; python_version <= '3.3'

src/klein/test/test_app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import sys
44

5-
from mock import Mock, patch
5+
try:
6+
from unittest.mock import Mock, patch
7+
except Exception:
8+
from mock import Mock, patch # type:ignore
69

710
from twisted.python.components import registerAdapter
811
from twisted.trial import unittest

src/klein/test/test_resource.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import os
44
from io import BytesIO
55

6-
from mock import Mock, call
6+
try:
7+
from unittest.mock import Mock, call
8+
except Exception:
9+
from mock import Mock, call # type:ignore
710

811
from six.moves.urllib.parse import parse_qs
912

0 commit comments

Comments
 (0)
0