From 83e18099c1c935b32ea309d851f4644ae883a126 Mon Sep 17 00:00:00 2001 From: Feroz Salam Date: Tue, 18 May 2021 08:18:36 +0100 Subject: [PATCH 1/2] Speed up unit tests by adding default parallelism - Also update pytest to a newer version, making other changes required to enable this - On a six-core machine, the test suite now runs in 8s as opposed to ~40s - On a single-core machine, the test suite now runs in ~60s as opposed to ~85s - Have also removed one incorrect use of `raises()` which has been deprecated --- requirements-dev.txt | 3 ++- tests/base_test.py | 12 ++++++------ tests/loaders_test.py | 2 +- tox.ini | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index a64fe430..c94d8dc3 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,7 +5,8 @@ m2r2 pluggy>=0.12.0 pre-commit pylint<2.9 -pytest<3.7.0 +pytest==6.0.0 +pytest-xdist==2.2.1 setuptools sphinx_rtd_theme tox==3.23.1 diff --git a/tests/base_test.py b/tests/base_test.py index b86498b1..cbb41272 100644 --- a/tests/base_test.py +++ b/tests/base_test.py @@ -1159,7 +1159,7 @@ def test_wait_until_responsive(ea): ] -def test_wait_until_responsive_timeout_es_not_available(ea, capsys): +def test_wait_until_responsive_timeout_es_not_available(ea, caplog): """Bail out if ElasticSearch doesn't (quickly) become responsive.""" # Never becomes responsive :-) @@ -1175,8 +1175,8 @@ def test_wait_until_responsive_timeout_es_not_available(ea, capsys): assert exc.value.code == 1 # Ensure we get useful diagnostics. - output, errors = capsys.readouterr() - assert 'Could not reach ElasticSearch at "es:14900".' in errors + user, level, message = caplog.record_tuples[0] + assert 'Could not reach ElasticSearch at "es:14900".' in message # Slept until we passed the deadline. sleep.mock_calls == [ @@ -1186,7 +1186,7 @@ def test_wait_until_responsive_timeout_es_not_available(ea, capsys): ] -def test_wait_until_responsive_timeout_index_does_not_exist(ea, capsys): +def test_wait_until_responsive_timeout_index_does_not_exist(ea, caplog): """Bail out if ElasticSearch doesn't (quickly) become responsive.""" # Never becomes responsive :-) @@ -1202,8 +1202,8 @@ def test_wait_until_responsive_timeout_index_does_not_exist(ea, capsys): assert exc.value.code == 1 # Ensure we get useful diagnostics. - output, errors = capsys.readouterr() - assert 'Writeback alias "wb_a" does not exist, did you run `elastalert-create-index`?' in errors + user, level, message = caplog.record_tuples[0] + assert 'Writeback alias "wb_a" does not exist, did you run `elastalert-create-index`?' in message # Slept until we passed the deadline. sleep.mock_calls == [ diff --git a/tests/loaders_test.py b/tests/loaders_test.py index be29dfa9..c45c73ce 100644 --- a/tests/loaders_test.py +++ b/tests/loaders_test.py @@ -347,7 +347,7 @@ def test_raises_on_missing_config(): mock_rule_open.return_value = test_rule_copy with mock.patch('os.walk') as mock_walk: mock_walk.return_value = [('', [], ['testrule.yaml'])] - with pytest.raises(EAException, message='key %s should be required' % key): + with pytest.raises(EAException): rules = load_conf(test_args) rules['rules'] = rules['rules_loader'].load(rules) diff --git a/tox.ini b/tox.ini index 47e62caa..52a8cbbe 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,7 @@ envlist = py39,docs [testenv] deps = -rrequirements-dev.txt commands = - coverage run --source=elastalert/,tests/ -m pytest --strict {posargs} + coverage run --source=elastalert/,tests/ -m pytest --strict -n 4 {posargs} coverage report -m flake8 . From fbf9916f80f6a8a0a69a36eadb2a720e88bb7703 Mon Sep 17 00:00:00 2001 From: Feroz Salam Date: Tue, 18 May 2021 08:25:16 +0100 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5baaa02..6ce88898 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,17 @@ ## Other changes - None +# Unreleased + +## Breaking changes +- None + +## New features +- None + +## Other changes +- Speed up unit tests by adding default parallelism - [164](https://github.com/jertel/elastalert2/pull/164) - @ferozsalam + # 2.1.0 ## Breaking changes