Skip to content

Flaky tests in api_test.py due to shared global state #168

@pem70

Description

@pem70

Description

The tests in tests/api_test.py have flakiness and lack proper isolation. They rely on shared global state pook.api engine and manual cleanup within the test bodies.

If a single test fails or crashes before it reaches its manual cleanup step, it pollutes the global environment. This causes all subsequent tests to fail because they expect a clean environment at the start of execution.

For example, in the following test:

def test_activate(engine):
    assert engine.active is False
    api.activate()
    assert engine.active is True
    api.disable()
    assert engine.active is False

If assert engine.active is True fails, the tests will end before cleaning up. All the following tests would fail because engine was left active by the first failing test.

Expected Behavior

Tests should be atomic and isolated. A failure in test_activate() should result in exactly 1 failure. The remaining tests should pass, as their logic is correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions