diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2024-10-30 13:16:31 +0100 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2024-11-29 15:26:03 +0100 |
commit | bb04699b17e014089e6dd6d0af2f01b9717ad58c (patch) | |
tree | b5667872712a7bd7c15c112eb23d3e3c75008b94 /tests/unit/test_results.py | |
parent | 6948689d2a2a29f7ffc5ca9d212e76a3e8e43956 (diff) | |
download | searxng-bb04699b17e014089e6dd6d0af2f01b9717ad58c.tar.gz searxng-bb04699b17e014089e6dd6d0af2f01b9717ad58c.zip |
[fix] unit tests: call searx.search.initialize in test's setUp
Depending on the order the unit tests are executed, the searx.search module is
initalized or not, issue reported in [1]::
Traceback (most recent call last):
File "searxng/tests/unit/test_results.py", line 72, in test_result_merge_by_title
self.container.extend('stract', [fake_result(engine='stract', title='short title')])
File "searxng/searx/results.py", line 243, in extend
histogram_observe(standard_result_count, 'engine', engine_name, 'result', 'count')
File "searxng/searx/metrics/__init__.py", line 49, in histogram_observe
histogram_storage.get(*args).observe(duration)
^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'
To ensure that the searx.search module is initialized, the
- searx.engines.load_engines is replace by
- searx.search.initialize
[1] https://github.com/searxng/searxng/pull/3932#discussion_r1822406569
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'tests/unit/test_results.py')
-rw-r--r-- | tests/unit/test_results.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/tests/unit/test_results.py b/tests/unit/test_results.py index 608d3c8c3..740d36a03 100644 --- a/tests/unit/test_results.py +++ b/tests/unit/test_results.py @@ -2,7 +2,7 @@ # pylint: disable=missing-module-docstring from searx.results import ResultContainer -from searx.engines import load_engines +import searx.search from tests import SearxTestCase @@ -36,17 +36,16 @@ def fake_result(url='https://aa.bb/cc?dd=ee#ff', title='aaa', content='bbb', eng class ResultContainerTestCase(SearxTestCase): # pylint: disable=missing-class-docstring + def setUp(self) -> None: stract_engine = make_test_engine_dict(name="stract", engine="stract", shortcut="stra") duckduckgo_engine = make_test_engine_dict(name="duckduckgo", engine="duckduckgo", shortcut="ddg") mojeek_engine = make_test_engine_dict(name="mojeek", engine="mojeek", shortcut="mjk") - - load_engines([stract_engine, duckduckgo_engine, mojeek_engine]) - + searx.search.initialize([stract_engine, duckduckgo_engine, mojeek_engine]) self.container = ResultContainer() def tearDown(self): - load_engines([]) + searx.search.load_engines([]) def test_empty(self): self.assertEqual(self.container.get_ordered_results(), []) |