Skip to content

Commit 4352eb3

Browse files
authored
refactor: conditional installation of mock (#53) (#54)
* refactor: conditional installation of mock (#53) * (chore): add markers for mock package in pyproject.toml * (refactor): try to import mock from unittest first * (refactor): update imports order according to pep08 see: https://peps.python.org/pep-0008/#imports * refactor: conditional installation of mock (#53) * (fix): failing tests for python3 < 3.8 caused by mock doesn't define '__iter__()' method for 'mock_open()'
1 parent a0e9725 commit 4352eb3

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pytest = [
2727
]
2828
flake8 = "^3.9.2"
2929
pytest-coverage = "*"
30-
mock = "*"
30+
mock = { version = "*", markers = "python_version < '3.8'" }
3131
more-itertools = "*"
3232

3333
[build-system]

tests/test_kernelcare.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import pytest
2-
import mock
3-
4-
import uchecker
1+
import sys
52

63
try:
74
from cStringIO import StringIO
85
except ImportError:
96
from io import StringIO
107

8+
import pytest
9+
if sys.version_info < (3, 8):
10+
import mock
11+
else:
12+
from unittest import mock
13+
14+
import uchecker
15+
1116

1217
LIBCARE_INFO_OUT = '{"pid": 20025, "comm": "sshd" , '\
1318
'"libc-2.17.so": {"buildid": "f9fafde281e0e0e2af45911ad0fa115b64c2cea8", "patchlvl": 2021021205}, '\

0 commit comments

Comments
 (0)