Skip to content

Commit

Permalink
Merge pull request #2142 from certtools/python-3.10
Browse files Browse the repository at this point in the history
TST: also test on python 3.10, switch to pytest
  • Loading branch information
aaronkaplan authored Feb 1, 2022
2 parents 169aab7 + 0a9a6db commit 1dc5364
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9']
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']

steps:
- name: Checkout repository
Expand Down
22 changes: 12 additions & 10 deletions .github/workflows/nosetests.yml → .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#Github Workflow to run nosetest tests
#Github Workflow to run unit tests with pytest
#
#SPDX-FileCopyrightText: 2020 IntelMQ Team <[email protected]>
#SPDX-FileCopyrightText: 2020 IntelMQ Team <[email protected]>, 2022 Sebastian Wagner <[email protected]>
#SPDX-License-Identifier: AGPL-3.0-or-later
#
name: "Nosetest test suite"
name: "Unit tests"
on:
push:
branches: [develop, maintenance, master]
Expand All @@ -15,13 +15,13 @@ on:
- '.github/**'

jobs:
nosetest:
unittests:
runs-on: ubuntu-latest
name: Run nosetest test suite
name: Run unit tests with pytest
strategy:
fail-fast: false
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9']
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
type: ['full', 'basic']

services:
Expand Down Expand Up @@ -65,20 +65,22 @@ jobs:
run: bash .github/workflows/scripts/setup-full.sh

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

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

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

- name: Run full testsuite
if: ${{ matrix.type == 'full' }}
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 {} \+
run: TZ=utc INTELMQ_TEST_DATABASES=1 INTELMQ_TEST_EXOTIC=1 pytest --cov intelmq/ --cov-report=xml --cov-branch intelmq/ contrib/

- name: Run codecov
if: ${{ matrix.type == 'full' }}
run: codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ CHANGELOG
- Add GitHub Action to run regexploit on all Python, JSON and YAML files (PR#2059 by Sebastian Wagner).
- `intelmq.lib.test`:
- Decorator `skip_ci` also detects `dpkg-buildpackage` environments by checking the environment variable `DEB_BUILD_ARCH` (PR#2123 by Sebastian Wagner).
- Also test on Python 3.10 (PR#2140 by Sebastian Wagner).
- Switch from nosetests to pytest, as the former does not support Python 3.10 (PR#2140 by Sebastian Wagner).

### Tools

Expand Down
2 changes: 1 addition & 1 deletion contrib/malware_name_mapping/test_download_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_parser_default_argument(self):

def test_parser_no_default(self):
parser = create_parser()
args = parser.parse_args()
args = parser.parse_args([])
self.assertEqual(args.add_default, None)


Expand Down
8 changes: 4 additions & 4 deletions docs/dev/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ Run the tests
All changes have to be tested and new contributions should be accompanied by according unit tests.
Please do not run the tests as root just like any other IntelMQ component for security reasons. Any other unprivileged user is possible.

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

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

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

* `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.
* `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.
* `INTELMQ_SKIP_INTERNET`: tests requiring internet connection will be skipped if this is set to 1.
* `INTELMQ_SKIP_REDIS`: redis-related tests are ran by default, set this to 1 to skip those.
* `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.
Expand All @@ -171,7 +171,7 @@ For example, to run all tests you can use:

.. code-block:: bash
INTELMQ_TEST_DATABASES=1 INTELMQ_TEST_EXOTIC=1 nosetests3
INTELMQ_TEST_DATABASES=1 INTELMQ_TEST_EXOTIC=1 pytest intelmq/tests/
Configuration test files
------------------------
Expand Down
2 changes: 1 addition & 1 deletion intelmq/lib/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def run_bot(self, iterations: int = 1, error_on_pipeline: bool = False,

""" Test if bot log messages are correctly formatted. """
self.assertLoglineMatches(0, "{} initialized with id {} and intelmq [0-9a-z.]* and python"
r" [0-9a-z.]{{5,8}}\+? \([a-zA-Z0-9,:. ]+\)( \[GCC\])?"
r" [0-9a-z.]{{5,8}}\+? \(.+?\)( \[GCC.*?\])?"
r" as process [0-9]+\."
"".format(self.bot_name,
self.bot_id), "INFO")
Expand Down
Empty file.
5 changes: 3 additions & 2 deletions intelmq/tests/bots/experts/jinja/test_expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
}


@test.skip_exotic()
class TestJinjaExpertBot(test.BotTestCase, unittest.TestCase):
"""
A TestCase for JinjaExpertBot.
Expand All @@ -51,9 +52,9 @@ def set_bot(cls):
cls.bot_reference = JinjaExpertBot

def test_jinja1(self):
self.sysconfig = {'fields': { 'feed.url': "{{ msg['feed.url'] | upper }}" } }
self.input_message = EXAMPLE_INPUT
self.run_bot()
self.run_bot(parameters={'fields': { 'feed.url': "{{ msg['feed.url'] | upper }}" },
'overwrite': True})
self.assertMessageEqual(0, EXAMPLE_OUTPUT1)

def test_jinja2(self):
Expand Down
8 changes: 8 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: 2022 Sebastian Wagner <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

[pytest]
# disable warning capture by pytest, so that logging can capture them
# https://docs.pytest.org/en/6.2.x/warnings.html#disabling-warning-capture-entirely
addopts: --cov intelmq/ --cov-report=xml --cov-branch -p no:warnings
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Security',
Expand Down

0 comments on commit 1dc5364

Please sign in to comment.