Skip to content

Chapter 5 - Test is checking the wrong session instance #126

Description

@V-H-R-Oliveira

The current test implementation in test_services.py is not testing the correct committed session. The session variable is being overwritten in the wrong place.

Current Implementation

https://github.com/cosmicpython/code/blob/chapter_05_high_gear_low_gear/tests/unit/test_services.py#L49C1-L54C37

def test_commits():
    repo, session = FakeRepository([]), FakeSession()
    session = FakeSession()  # useless overwrite 
    services.add_batch("b1", "OMINOUS-MIRROR", 100, None, repo, session)
    services.allocate("o1", "OMINOUS-MIRROR", 10, repo, session)
    assert session.committed is True

The correct test implementation should pass independent sessions or ensure the tracked session is the one actually being asserted:

def test_commits():
    repo = FakeRepository([])
    services.add_batch("b1", "OMINOUS-MIRROR", 100, None, repo, FakeSession())
    
    session = FakeSession()
    services.allocate("o1", "OMINOUS-MIRROR", 10, repo, session)
    
    assert session.committed is True

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions