Skip to content

Commit ea7267d

Browse files
committed
fix(test): deregister needs_update bars from global capture registry
test_needs_update starts bars (registering them as global capture listeners via streams.start_capturing) but never finish()es them, and one deliberately sets term_width='wide' to prove the width-threshold math now propagates. That poisoned bar lingered in streams.listeners, so when a *later* test wrote a newline to the captured stream -- WrappingIO.write calls update() on every listener -- the abandoned bar hit the int/str division from commit 84b9413 and raised, intermittently failing test_examples and test_no_newlines (the failure surfaced or hid depending on freezegun-driven redraw timing). Add an autouse fixture that deregisters whatever each test started, so a bar driven into an invalid state can never poison another test.
1 parent 43f11d1 commit ea7267d

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

tests/test_needs_update.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
import pytest
1616

1717
import progressbar
18+
from progressbar import utils
19+
20+
21+
@pytest.fixture(autouse=True)
22+
def _deregister_started_bars() -> typing.Iterator[None]:
23+
# start() registers each bar as a global capture listener (so writes to
24+
# the wrapped stream redraw it). These tests deliberately drive bars into
25+
# invalid states -- e.g. a non-numeric term_width -- and never finish()
26+
# them. Deregister whatever this test started so a poisoned bar cannot be
27+
# update()d when a *later* test writes a newline to the captured stream.
28+
before = set(utils.streams.listeners)
29+
yield
30+
for bar in list(utils.streams.listeners - before):
31+
utils.streams.stop_capturing(bar)
1832

1933

2034
def _bar(**kwargs: typing.Any) -> progressbar.ProgressBar:

0 commit comments

Comments
 (0)