Skip to content

Commit 809e4ef

Browse files
committed
chore(test): modernise and skip db2 tests on arm64
- add pytest skip to ibm_db2 tests on arm64 and mark module as x86_64 only in requirements-dev.txt - move 'testing' helpers module under tests/ and load via conftest for better compatibility when testing installed module / under venv Signed-off-by: Dominic Evans <[email protected]>
1 parent cb803c6 commit 809e4ef

File tree

11 files changed

+29
-11
lines changed

11 files changed

+29
-11
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ repos:
1111
- id: double-quote-string-fixer
1212
- id: end-of-file-fixer
1313
- id: name-tests-test
14+
exclude: "^tests/testing/.*$"
1415
- id: trailing-whitespace
1516
- repo: https://github.com/pycqa/flake8
1617
rev: 3.9.2

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ responses
1212
tox-pip-extensions
1313
tox>=3.8
1414
unidiff
15-
ibm_db
15+
ibm_db; platform_machine == 'x86_64'
1616
boxsdk[jwt]
1717
pyahocorasick
1818
tabulate

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ description-file = README.md
33

44
[wheel]
55
universal = True
6+
7+
[tool:pytest]
8+
norecursedirs=tests/testing

tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import sys
2+
import os
3+
4+
sys.path.append(os.path.join(os.path.dirname(__file__), "testing"))

tests/main_test.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import json
2+
import platform
23
import shlex
34
import textwrap
45
from contextlib import contextmanager
56

67
import mock
78
import pytest
8-
9-
from detect_secrets import main as main_module
109
from detect_secrets import VERSION
10+
from detect_secrets import main as main_module
1111
from detect_secrets.core import audit as audit_module
1212
from detect_secrets.core.constants import POTENTIAL_SECRET_DETECTED_NOTE
1313
from detect_secrets.main import main
1414
from detect_secrets.plugins.common.util import import_plugins
15+
1516
from testing.factories import secrets_collection_factory
16-
from testing.mocks import Any
17-
from testing.mocks import mock_printer
17+
from testing.mocks import Any, mock_printer
1818
from testing.util import uncolor
1919

2020

@@ -190,6 +190,10 @@ def test_scan_string_cli_overrides_stdin(self):
190190
}, exclude=['Db2Detector'],
191191
)
192192

193+
@pytest.mark.skipif(
194+
platform.machine() not in ("x86_64", "AMD64"),
195+
reason="ibm_db2 only runs on x86_64",
196+
)
193197
def test_scan_string_cli_overrides_stdin_db2_enabled(self):
194198
with mock_stdin(
195199
'012345678ab',

tests/plugins/db2_test.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1+
import platform
12
import textwrap
23

34
import pytest
4-
from mock import MagicMock
5-
from mock import patch
6-
75
from detect_secrets.core.constants import VerifiedResult
86
from detect_secrets.core.potential_secret import PotentialSecret
9-
from detect_secrets.plugins.db2 import Db2Detector
10-
from detect_secrets.plugins.db2 import find_other_factor
11-
from detect_secrets.plugins.db2 import get_hostname_port_database_from_url
7+
try:
8+
from detect_secrets.plugins.db2 import (
9+
Db2Detector,
10+
find_other_factor,
11+
get_hostname_port_database_from_url,
12+
)
13+
except ModuleNotFoundError: # pragma: no cover
14+
if platform.machine() not in ("x86_64", "AMD64"):
15+
pytest.skip(reason="ibm_db2 module only runs on x86_64", allow_module_level=True)
16+
raise
1217

18+
from mock import MagicMock, patch
1319

1420
DB2_USER = 'fake_user'
1521
DB2_PASSWORD = 'fake_password'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)