summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2024-06-25 10:49:37 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-06-28 08:54:19 +0200
commitd80fcbc635c683c43c23dc2f297b543ef6c11d55 (patch)
treea36b96f1ac3ba60d40dad6ca218acea8028f98ec /tests/unit
parenta5f8e0899ce94f3ad81addad53af9cd88f684d16 (diff)
downloadsearxng-d80fcbc635c683c43c23dc2f297b543ef6c11d55.tar.gz
searxng-d80fcbc635c683c43c23dc2f297b543ef6c11d55.zip
[fix] unit test_xpath.py: name 'logger' is not defined
Depending on the order in which the unit tests are executed, the python modules of the engines are initialized (monkey patched) or not. As the order of the tests is not static, random errors may occur. To avaoid random `NameError: name 'logger' is not defined` in the unit tests of the xpath engine, a logger is monkey patched into the xpath py-module. ``` make test.unit TEST tests/unit ......EE................... ====================================================================== ERROR: test_response (tests.unit.engines.test_xpath.TestXpathEngine.test_response) ---------------------------------------------------------------------- Traceback (most recent call last): File "./tests/unit/engines/test_xpath.py", line 60, in test_response self.assertEqual(xpath.response(response), []) ^^^^^^^^^^^^^^^^^^^^^^^^ File "./searx/engines/xpath.py", line 309, in response logger.debug("found %s results", len(results)) ^^^^^^ NameError: name 'logger' is not defined ====================================================================== ERROR: test_response_results_xpath (tests.unit.engines.test_xpath.TestXpathEngine.test_response_results_xpath) ---------------------------------------------------------------------- Traceback (most recent call last): File "./tests/unit/engines/test_xpath.py", line 102, in test_response_results_xpath self.assertEqual(xpath.response(response), []) ^^^^^^^^^^^^^^^^^^^^^^^^ File "./searx/engines/xpath.py", line 309, in response logger.debug("found %s results", len(results)) ^^^^^^ NameError: name 'logger' is not defined ``` Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/engines/test_xpath.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/unit/engines/test_xpath.py b/tests/unit/engines/test_xpath.py
index 380dd1d6c..e80ef96e2 100644
--- a/tests/unit/engines/test_xpath.py
+++ b/tests/unit/engines/test_xpath.py
@@ -3,9 +3,14 @@
from collections import defaultdict
import mock
+
from searx.engines import xpath
+from searx import logger
+
from tests import SearxTestCase
+logger = logger.getChild('engines')
+
class TestXpathEngine(SearxTestCase): # pylint: disable=missing-class-docstring
html = """
@@ -23,6 +28,9 @@ class TestXpathEngine(SearxTestCase): # pylint: disable=missing-class-docstring
</div>
"""
+ def setUp(self):
+ xpath.logger = logger.getChild('test_xpath')
+
def test_request(self):
xpath.search_url = 'https://url.com/{query}'
xpath.categories = []