Skip to content

Commit 6d4d889

Browse files
authored
Merge pull request #2370 from wagner-intevation/fix-2369
tst: skip tests which require an intelmq installation by default
2 parents a70fa70 + 46fd196 commit 6d4d889

File tree

6 files changed

+28
-3
lines changed

6 files changed

+28
-3
lines changed

.github/workflows/unittests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,9 @@ jobs:
7575

7676
- name: Run full testsuite
7777
if: ${{ matrix.type == 'full' }}
78-
run: TZ=utc INTELMQ_TEST_DATABASES=1 INTELMQ_TEST_EXOTIC=1 pytest --cov intelmq/ --cov-report=xml --cov-branch intelmq/ contrib/
78+
run: pytest --cov intelmq/ --cov-report=xml --cov-branch intelmq/ contrib/
79+
env:
80+
TZ: utz
81+
INTELMQ_TEST_DATABASES: 1
82+
INTELMQ_TEST_EXOTIC: 1
83+
INTELMQ_TEST_INSTALLATION: 1

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ CHANGELOG
5353
### Documentation
5454

5555
### Tests
56+
- New decorator `skip_installation` and environment variable `INTELMQ_TEST_INSTALLATION` to skip tests requiring an IntelMQ installation on the test host by default (PR#2370 by Sebastian Wagner, fixes #2369)
5657

5758
### Packaging
5859

docs/dev/guide.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,13 @@ There are a bunch of environment variables which switch on/off some tests:
238238
* `INTELMQ_TEST_EXOTIC`: some bots and tests require libraries which may not be available, those are skipped by default. To run them, set this to 1.
239239
* `INTELMQ_TEST_REDIS_PASSWORD`: Set this value to the password for the local redis database if needed.
240240
* `INTELMQ_LOOKYLOO_TEST`: Set this value to run the lookyloo tests. Public lookyloo instance will be used as default.
241+
* `INTELMQ_TEST_INSTALLATION`: Set this value to run tests which require a local IntelMQ installation, such as for testing the command lines tools relying on configuration files, dump files etc.
241242

242243
For example, to run all tests you can use:
243244

244245
.. code-block:: bash
245246
246-
INTELMQ_TEST_DATABASES=1 INTELMQ_TEST_EXOTIC=1 pytest intelmq/tests/
247+
INTELMQ_TEST_DATABASES=1 INTELMQ_TEST_EXOTIC=1 INTELMQ_TEST_INSTALLATION=1 pytest intelmq/tests/
247248
248249
Configuration test files
249250
------------------------

intelmq/lib/test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import unittest
1818
import unittest.mock as mock
1919
from itertools import chain
20-
from sys import version_info
2120

2221
import pkg_resources
2322
import redis
@@ -111,6 +110,14 @@ def skip_build_environment():
111110
return unittest.skipIf(os.getenv('USER') == 'abuild', 'Test disabled in Build Service.')
112111

113112

113+
def skip_installation():
114+
"""
115+
Skip a test that requires an IntelMQ installation on this host
116+
"""
117+
return unittest.skipUnless(os.getenv('INTELMQ_TEST_INSTALLATION'),
118+
'Skipping tests requiring an IntelMQ installation.')
119+
120+
114121
class BotTestCase:
115122
"""
116123
Provides common tests and assert methods for bot testing.

intelmq/tests/bin/test_intelmqctl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import intelmq.bin.intelmqctl as ctl
1414
import intelmq.lib.utils as utils
15+
from intelmq.lib.test import skip_installation
1516

1617

1718
class TestIntelMQProcessManager(unittest.TestCase):
@@ -100,16 +101,19 @@ def tearDown(self):
100101
self.tmp_config_dir.cleanup()
101102
return super().tearDown()
102103

104+
@skip_installation()
103105
def test_check_passed_with_default_harmonization_and_empty_runtime(self):
104106
self._load_default_harmonization()
105107
self.assertEqual((0, 'success'), self.intelmqctl.check(no_connections=True, check_executables=False))
106108

109+
@skip_installation()
107110
def test_check_pass_with_default_runtime(self):
108111
with mock.patch.object(ctl.utils, "RUNTIME_CONF_FILE", self.tmp_runtime):
109112
self._load_default_harmonization()
110113
self._load_default_runtime()
111114
self.assertEqual((0, 'success'), self.intelmqctl.check(no_connections=True, check_executables=False))
112115

116+
@skip_installation()
113117
@mock.patch.object(ctl.importlib, "import_module", mock.Mock(side_effect=SyntaxError))
114118
def test_check_handles_syntaxerror_when_importing_bots(self):
115119
self._load_default_harmonization()

intelmq/tests/bin/test_intelmqdump.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import termstyle
1515

1616
from intelmq.bin import intelmqdump
17+
from intelmq.lib.test import skip_installation
1718

1819

1920
class TestCompleter(unittest.TestCase):
@@ -95,6 +96,7 @@ def _run_main(self, argv: list) -> str:
9596
intelmqdump.main(argv)
9697
return output.getvalue().split("\n")
9798

99+
@skip_installation()
98100
@mock.patch.object(intelmqdump, "input", return_value='q')
99101
def test_list_dumps_for_all_bots_from_default_log_path(self, _):
100102
self._prepare_empty_dump('test-1')
@@ -106,6 +108,7 @@ def test_list_dumps_for_all_bots_from_default_log_path(self, _):
106108
self.assertIn("0: test-1 empty file", output[1])
107109
self.assertIn("1: test-2 empty file", output[2])
108110

111+
@skip_installation()
109112
@mock.patch.object(intelmqdump, "input", return_value='q')
110113
def test_list_dumps_for_all_bots_from_custom_locations(self, _):
111114
self.global_config = {"logging_path": self.tmp_log_dir.name}
@@ -130,6 +133,7 @@ def test_list_dumps_for_all_bots_from_custom_locations(self, _):
130133
self.assertIn("0: test-1 empty file", output[1])
131134
self.assertIn("1: test-2 empty file", output[2])
132135

136+
@skip_installation()
133137
@mock.patch.object(intelmqdump, "input")
134138
def test_list_and_select_dump_from_global_location(self, input_mock):
135139
self._prepare_empty_dump('test-1')
@@ -145,6 +149,7 @@ def test_list_and_select_dump_from_global_location(self, input_mock):
145149
# Enough to check that the correct file path was used
146150
self.assertIn("Processing test-1: empty file", output[2])
147151

152+
@skip_installation()
148153
@mock.patch.object(intelmqdump, "input")
149154
def test_list_and_select_dump_from_custom_location(self, input_mock):
150155
self.global_config = {"logging_path": self.tmp_log_dir.name}
@@ -166,6 +171,7 @@ def test_list_and_select_dump_from_custom_location(self, input_mock):
166171
# Enough to check that the correct file path was used
167172
self.assertIn("Processing test-1: empty file", output[2])
168173

174+
@skip_installation()
169175
@mock.patch.object(intelmqdump, "input")
170176
def test_selecting_dump_warns_when_filename_is_ambiguous(self, input_mock):
171177
"""With different locations used, there could be a case of dumps with the same
@@ -197,6 +203,7 @@ def test_selecting_dump_warns_when_filename_is_ambiguous(self, input_mock):
197203
output = self._run_main([])
198204
self.assertIn("Processing test-1: empty file", output[3])
199205

206+
@skip_installation()
200207
@mock.patch.object(intelmqdump, "input", return_value='q')
201208
def test_get_dump_for_one_bot(self, _):
202209
self._prepare_empty_dump("bot/bot-1")

0 commit comments

Comments
 (0)