Skip to content

Empty graph tests fail due to leftover data from module-scoped fixtures #126

@mykola-pereyma

Description

@mykola-pereyma

Describe the bug

test_louvain_communities_empty_graph and test_pagerank_empty_graph integration tests fail because prior test methods in the same module sync data to Neptune via the neptune_graph fixture (module-scoped, autouse), and that data is never cleaned up between individual test methods. The empty graph tests create a local empty graph and pass it to the algorithm with backend='neptune', but the Neptune instance still contains nodes and edges from earlier tests.

To Reproduce

  1. Set NETWORKX_GRAPH_ID to a running Neptune Analytics graph
  2. Run python -m pytest integ_test/test_algo_louvain.py -v --tb=short
  3. Observe test_louvain_communities_empty_graph fails with assert 2 == 0 (gets 2 communities from leftover data)
  4. Run python -m pytest integ_test/test_algo_page_rank.py -v --tb=short
  5. Observe test_pagerank_empty_graph fails with assert 6 == 0 (gets 6 node scores from leftover data)

Expected behavior

Both empty graph tests should return empty results:

  • test_louvain_communities_empty_graph: len(result) == 0
  • test_pagerank_empty_graph: len(r) == 0

Screenshots

FAILED integ_test/test_algo_louvain.py::TestLouvain::test_louvain_communities_empty_graph
AssertionError: assert 2 == 0
where 2 = len([{'A', 'B', 'C'}, {'D', 'E', 'F'}])

FAILED integ_test/test_algo_page_rank.py::TestPageRank::test_pagerank_empty_graph
AssertionError: assert 6 == 0
where 6 = len({'A': 0.0291, 'B': 0.0538, 'C': 0.3152, 'D': 0.2962, ...})

Desktop (please complete the following information):

  • OS: macOS
  • Version: nx-neptune 0.5.0

Additional context

Root cause: neptune_graph fixture is scope='module' and autouse=True. Earlier test methods use test_graph/test_digraph fixtures that sync nodes (A-F) and edges to Neptune. No cleanup happens between test methods. The empty graph tests run last by source order and inherit the Neptune state.

Suggested fix: add a clear_graph() call before the empty/single-node tests, either via a fixture or at the start of the test method.

Affected tests:

  • integ_test/test_algo_louvain.py::TestLouvain::test_louvain_communities_empty_graph
  • integ_test/test_algo_page_rank.py::TestPageRank::test_pagerank_empty_graph

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions