Skip to content

fix: Prevent Mock object issues in graph memory tests#3627

Merged
parshvadaftari merged 2 commits intomem0ai:mainfrom
ron-42:fix/test-mock-threshold-config
Oct 21, 2025
Merged

fix: Prevent Mock object issues in graph memory tests#3627
parshvadaftari merged 2 commits intomem0ai:mainfrom
ron-42:fix/test-mock-threshold-config

Conversation

@ron-42
Copy link
Copy Markdown
Contributor

@ron-42 ron-42 commented Oct 19, 2025

Fix: Prevent Mock Object Issues in Graph Memory Tests

Context

This PR fixes test failures identified in the CI pipeline for PR #3593: #3593 (comment)

The failing tests were reported by @parshvadaftari in the review comments, visible in the CI run:
https://github.com/mem0ai/mem0/actions/runs/18632251788/job/53118610490?pr=3625

Problem

Tests for graph memory implementations (Kuzu, Neptune Analytics, and Neptune DB) were failing with errors like:

AssertionError: assert <Mock name='mock.graph_store.threshold' id='...'> == 0.7

And runtime errors:

RuntimeError: Unknown parameter type <class 'unittest.mock.Mock'>

Root Cause

When using MagicMock() or Mock() in Python tests, accessing an undefined attribute automatically creates a new Mock object rather than returning a concrete value.

In the graph memory implementations, the code checks for threshold configuration:

self.threshold = self.config.graph_store.threshold if hasattr(self.config.graph_store, "threshold") else 0.7

When test fixtures used config = Mock() or config = MagicMock() without explicitly setting the threshold attribute, accessing config.graph_store.threshold would:

  1. Return a Mock object instead of 0.7
  2. Pass this Mock object through the code
  3. Cause assertion failures when comparing Mock vs numeric values
  4. Cause runtime errors when functions expected numeric parameters

Solution

Explicitly set config.graph_store.threshold = 0.7 in all test fixtures to ensure the implementation receives actual numeric values instead of Mock objects.

Files Changed

tests/memory/test_kuzu.py

  • Added config.graph_store.threshold = 0.7 in the mock_config fixture

tests/memory/test_neptune_analytics_memory.py

  • Added self.config.graph_store.threshold = 0.7 in setUp method
  • Updated test_add_entities assertions to expect threshold=0.7 instead of threshold=0.9 (matching actual implementation behavior)

tests/memory/test_neptune_memory.py

  • Added self.config.graph_store.threshold = 0.7 in setUp method
  • Updated test_add_entities assertions to expect threshold=0.7 instead of threshold=0.9 (matching actual implementation behavior)

Test Results

All Mock-related test failures now pass:

tests/memory/test_kuzu.py::TestKuzu::test_kuzu_memory_initialization PASSED
tests/memory/test_neptune_analytics_memory.py::TestNeptuneMemory::test_initialization PASSED
tests/memory/test_neptune_analytics_memory.py::TestNeptuneMemory::test_add_entities PASSED
tests/memory/test_neptune_memory.py::TestNeptuneMemory::test_initialization PASSED
tests/memory/test_neptune_memory.py::TestNeptuneMemory::test_add_entities PASSED

Note on Remaining Failures

There is one additional test failure (tests/memory/test_kuzu.py::TestKuzu::test_kuzu) that is unrelated to the Mock threshold issue. This appears to be a separate bug in the Kuzu graph implementation logic where the destination node is incorrectly resolved to 'bob' instead of 'charlie'. This is a different issue that should be addressed in a separate PR.

From the CI logs:

AssertionError: assert [{'source': 'bob', 'relationship': 'knows', 'target': 'bob'}] 
                    == [{'source': 'bob', 'relationship': 'knows', 'target': 'charlie'}]

This PR specifically addresses the 5 Mock-related test failures mentioned in the review comments.

Impact

  • ✅ Fixes 5 failing tests related to Mock threshold configuration
  • ✅ No changes to production code - only test fixtures
  • ✅ Ensures consistent behavior across all graph memory implementations
  • ✅ Prevents future Mock-related test failures
  • ℹ️ One unrelated Kuzu test failure remains (separate implementation bug)

Testing

Tested locally with:

hatch run dev_py_3_10:test tests/memory/test_kuzu.py::TestKuzu::test_kuzu_memory_initialization
hatch run dev_py_3_10:test tests/memory/test_neptune_analytics_memory.py
hatch run dev_py_3_10:test tests/memory/test_neptune_memory.py

All tests pass successfully.

…ject issues

When using MagicMock or Mock objects in tests, accessing an undefined
attribute like  automatically creates a
new Mock object instead of returning a concrete value. This caused test
failures where:

1. Assertions expected numeric threshold values (0.7) but received Mock objects
2. Runtime errors occurred when Mock objects were passed as parameters to
   functions expecting numeric values (e.g., Kuzu query execution)

Fixed by explicitly setting  in test
fixtures for:
- tests/memory/test_kuzu.py
- tests/memory/test_neptune_analytics_memory.py
- tests/memory/test_neptune_memory.py

Also updated test assertions in test_add_entities methods to expect the
default threshold value of 0.7 (from config) instead of 0.9, matching
the actual implementation behavior where _add_entities uses self.threshold.
@parshvadaftari
Copy link
Copy Markdown
Contributor

parshvadaftari commented Oct 21, 2025

Hey @ron-42 The tests are failing for this pr as well, can you please fix it? The failing test is related to kuzu, but that can be fixed you can update the test for kuzu.

@parshvadaftari parshvadaftari merged commit eb2f8a3 into mem0ai:main Oct 21, 2025
5 of 7 checks passed
garciaba79 pushed a commit to garciaba79/mem0 that referenced this pull request Feb 12, 2026
Co-authored-by: parshvadaftari <daftariparshva@gmail.com>
jamebobob pushed a commit to jamebobob/mem0-vigil-recall that referenced this pull request Mar 29, 2026
Co-authored-by: parshvadaftari <daftariparshva@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants