Skip to content

Commit 1dc5364

Browse files
authored
Merge pull request #2142 from certtools/python-3.10
TST: also test on python 3.10, switch to pytest
2 parents 169aab7 + 0a9a6db commit 1dc5364

File tree

10 files changed

+34
-19
lines changed

10 files changed

+34
-19
lines changed

.github/workflows/build-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
strategy:
2222
fail-fast: false
2323
matrix:
24-
python-version: ['3.6', '3.7', '3.8', '3.9']
24+
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
2525

2626
steps:
2727
- name: Checkout repository

.github/workflows/nosetests.yml renamed to .github/workflows/unittests.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#Github Workflow to run nosetest tests
1+
#Github Workflow to run unit tests with pytest
22
#
3-
#SPDX-FileCopyrightText: 2020 IntelMQ Team <[email protected]>
3+
#SPDX-FileCopyrightText: 2020 IntelMQ Team <[email protected]>, 2022 Sebastian Wagner <[email protected]>
44
#SPDX-License-Identifier: AGPL-3.0-or-later
55
#
6-
name: "Nosetest test suite"
6+
name: "Unit tests"
77
on:
88
push:
99
branches: [develop, maintenance, master]
@@ -15,13 +15,13 @@ on:
1515
- '.github/**'
1616

1717
jobs:
18-
nosetest:
18+
unittests:
1919
runs-on: ubuntu-latest
20-
name: Run nosetest test suite
20+
name: Run unit tests with pytest
2121
strategy:
2222
fail-fast: false
2323
matrix:
24-
python-version: ['3.6', '3.7', '3.8', '3.9']
24+
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
2525
type: ['full', 'basic']
2626

2727
services:
@@ -65,20 +65,22 @@ jobs:
6565
run: bash .github/workflows/scripts/setup-full.sh
6666

6767
- name: Install test dependencies
68-
run: pip install nose Cerberus requests_mock coverage codecov
68+
run: pip install pytest-cov Cerberus requests_mock coverage
6969

7070
- name: Install dependencies
7171
if: ${{ matrix.type == 'basic' }}
7272
run: pip install -e .
7373

7474
- name: Run basic testsuite
7575
if: ${{ matrix.type == 'basic' }}
76-
run: nosetests --with-coverage --cover-package=intelmq --cover-branches
76+
run: pytest --cov intelmq/ --cov-report=xml --cov-branch intelmq/
7777

7878
- name: Run full testsuite
7979
if: ${{ matrix.type == 'full' }}
80-
run: TZ=utc INTELMQ_TEST_DATABASES=1 INTELMQ_TEST_EXOTIC=1 nosetests --with-coverage --cover-package=intelmq --cover-branches; find contrib/ -name "test*.py" -exec nosetests {} \+
80+
run: TZ=utc INTELMQ_TEST_DATABASES=1 INTELMQ_TEST_EXOTIC=1 pytest --cov intelmq/ --cov-report=xml --cov-branch intelmq/ contrib/
8181

8282
- name: Run codecov
8383
if: ${{ matrix.type == 'full' }}
84-
run: codecov
84+
uses: codecov/codecov-action@v2
85+
with:
86+
fail_ci_if_error: true

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ CHANGELOG
9292
- Add GitHub Action to run regexploit on all Python, JSON and YAML files (PR#2059 by Sebastian Wagner).
9393
- `intelmq.lib.test`:
9494
- Decorator `skip_ci` also detects `dpkg-buildpackage` environments by checking the environment variable `DEB_BUILD_ARCH` (PR#2123 by Sebastian Wagner).
95+
- Also test on Python 3.10 (PR#2140 by Sebastian Wagner).
96+
- Switch from nosetests to pytest, as the former does not support Python 3.10 (PR#2140 by Sebastian Wagner).
9597

9698
### Tools
9799

contrib/malware_name_mapping/test_download_mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_parser_default_argument(self):
8989

9090
def test_parser_no_default(self):
9191
parser = create_parser()
92-
args = parser.parse_args()
92+
args = parser.parse_args([])
9393
self.assertEqual(args.add_default, None)
9494

9595

docs/dev/guide.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ Run the tests
142142
All changes have to be tested and new contributions should be accompanied by according unit tests.
143143
Please do not run the tests as root just like any other IntelMQ component for security reasons. Any other unprivileged user is possible.
144144

145-
You can run the tests by changing to the directory with IntelMQ repository and running either `unittest` or `nosetests`:
145+
You can run the tests by changing to the directory with IntelMQ repository and running either `unittest` or `pytest`:
146146

147147
.. code-block:: bash
148148
149149
cd /opt/dev_intelmq
150150
sudo -u intelmq python3 -m unittest {discover|filename} # or
151-
sudo -u intelmq nosetests3 [filename] # alternatively nosetests or nosetests-3.8 depending on your installation, or
151+
sudo -u intelmq pytest [filename]
152152
sudo -u intelmq python3 setup.py test # uses a build environment (no external dependencies)
153153
154154
Some bots need local databases to succeed. If you only want to test one explicit test file, give the file path as argument.
@@ -160,7 +160,7 @@ Environment variables
160160

161161
There are a bunch of environment variables which switch on/off some tests:
162162

163-
* `INTELMQ_TEST_DATABASES`: databases such as postgres, elasticsearch, mongodb are not tested by default. Set this environment variable to 1 to test those bots. These tests need preparation, e.g. running databases with users and certain passwords etc. Have a look at the `.github/workflows/nosetests.yml` and the corresponding `.github/workflows/scripts/setup-full.sh` in IntelMQ's repository for steps to set databases up.
163+
* `INTELMQ_TEST_DATABASES`: databases such as postgres, elasticsearch, mongodb are not tested by default. Set this environment variable to 1 to test those bots. These tests need preparation, e.g. running databases with users and certain passwords etc. Have a look at the `.github/workflows/unittests.yml` and the corresponding `.github/workflows/scripts/setup-full.sh` in IntelMQ's repository for steps to set databases up.
164164
* `INTELMQ_SKIP_INTERNET`: tests requiring internet connection will be skipped if this is set to 1.
165165
* `INTELMQ_SKIP_REDIS`: redis-related tests are ran by default, set this to 1 to skip those.
166166
* `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.
@@ -171,7 +171,7 @@ For example, to run all tests you can use:
171171

172172
.. code-block:: bash
173173
174-
INTELMQ_TEST_DATABASES=1 INTELMQ_TEST_EXOTIC=1 nosetests3
174+
INTELMQ_TEST_DATABASES=1 INTELMQ_TEST_EXOTIC=1 pytest intelmq/tests/
175175
176176
Configuration test files
177177
------------------------

intelmq/lib/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def run_bot(self, iterations: int = 1, error_on_pipeline: bool = False,
349349

350350
""" Test if bot log messages are correctly formatted. """
351351
self.assertLoglineMatches(0, "{} initialized with id {} and intelmq [0-9a-z.]* and python"
352-
r" [0-9a-z.]{{5,8}}\+? \([a-zA-Z0-9,:. ]+\)( \[GCC\])?"
352+
r" [0-9a-z.]{{5,8}}\+? \(.+?\)( \[GCC.*?\])?"
353353
r" as process [0-9]+\."
354354
"".format(self.bot_name,
355355
self.bot_id), "INFO")

intelmq/tests/bots/experts/jinja/__init__.py

Whitespace-only changes.

intelmq/tests/bots/experts/jinja/test_expert.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
}
4242

4343

44+
@test.skip_exotic()
4445
class TestJinjaExpertBot(test.BotTestCase, unittest.TestCase):
4546
"""
4647
A TestCase for JinjaExpertBot.
@@ -51,9 +52,9 @@ def set_bot(cls):
5152
cls.bot_reference = JinjaExpertBot
5253

5354
def test_jinja1(self):
54-
self.sysconfig = {'fields': { 'feed.url': "{{ msg['feed.url'] | upper }}" } }
5555
self.input_message = EXAMPLE_INPUT
56-
self.run_bot()
56+
self.run_bot(parameters={'fields': { 'feed.url': "{{ msg['feed.url'] | upper }}" },
57+
'overwrite': True})
5758
self.assertMessageEqual(0, EXAMPLE_OUTPUT1)
5859

5960
def test_jinja2(self):

pytest.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-FileCopyrightText: 2022 Sebastian Wagner <[email protected]>
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
[pytest]
6+
# disable warning capture by pytest, so that logging can capture them
7+
# https://docs.pytest.org/en/6.2.x/warnings.html#disabling-warning-capture-entirely
8+
addopts: --cov intelmq/ --cov-report=xml --cov-branch -p no:warnings

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
'Programming Language :: Python :: 3.6',
7878
'Programming Language :: Python :: 3.7',
7979
'Programming Language :: Python :: 3.8',
80+
'Programming Language :: Python :: 3.9',
81+
'Programming Language :: Python :: 3.10',
8082
'Programming Language :: Python :: 3 :: Only',
8183
'Programming Language :: Python :: Implementation :: CPython',
8284
'Topic :: Security',

0 commit comments

Comments
 (0)