Skip to content

Commit 74f8772

Browse files
Copilot4n4nd
andcommitted
Fix test module detection logic to avoid false positives
- Use exact module name matching instead of substring matching - Check for 'modulename' or 'modulename.*' pattern to avoid false positives - Prevents incorrect detection of modules with similar names Co-authored-by: 4n4nd <22333506+4n4nd@users.noreply.github.com>
1 parent 2447357 commit 74f8772

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

tests/test_lazy_imports.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def test_prometheus_connect_import_without_pandas_matplotlib_numpy(self):
3131

3232
# Check that pandas, matplotlib, and numpy are not loaded
3333
loaded_modules = sys.modules.keys()
34-
pandas_loaded = any('pandas' in m for m in loaded_modules)
35-
matplotlib_loaded = any('matplotlib' in m for m in loaded_modules)
36-
numpy_loaded = any('numpy' in m for m in loaded_modules)
34+
pandas_loaded = any(m == 'pandas' or m.startswith('pandas.') for m in loaded_modules)
35+
matplotlib_loaded = any(m == 'matplotlib' or m.startswith('matplotlib.') for m in loaded_modules)
36+
numpy_loaded = any(m == 'numpy' or m.startswith('numpy.') for m in loaded_modules)
3737

3838
self.assertFalse(pandas_loaded, "pandas should not be loaded when importing PrometheusConnect")
3939
self.assertFalse(matplotlib_loaded, "matplotlib should not be loaded when importing PrometheusConnect")
@@ -63,7 +63,7 @@ def test_prometheus_connect_instantiation_without_numpy(self):
6363

6464
# Check that numpy is still not loaded after instantiation
6565
loaded_modules = sys.modules.keys()
66-
numpy_loaded = any('numpy' in m for m in loaded_modules)
66+
numpy_loaded = any(m == 'numpy' or m.startswith('numpy.') for m in loaded_modules)
6767

6868
self.assertFalse(numpy_loaded, "numpy should not be loaded when instantiating PrometheusConnect")
6969
self.assertIsNotNone(pc, "PrometheusConnect should be instantiated successfully")
@@ -91,7 +91,7 @@ def test_metric_import_loads_pandas(self):
9191

9292
# Check that pandas is loaded (this is expected for Metric)
9393
loaded_modules = sys.modules.keys()
94-
pandas_loaded = any('pandas' in m for m in loaded_modules)
94+
pandas_loaded = any(m == 'pandas' or m.startswith('pandas.') for m in loaded_modules)
9595

9696
self.assertTrue(pandas_loaded, "pandas should be loaded when importing Metric")
9797

0 commit comments

Comments
 (0)