[BUG] test_placement_table_box_elements permanently mutates the shared box.ASCII singleton

#4223 · open · 1 comments

View on GitHub ↗

meagoodboy

- [x] I've checked docs and closed issues for possible solutions. - [x] I can't find my issue in the FAQ. **Describe the bug** `tests/test_table.py::test_placement_table_box_elements` builds a `Table` with the module-level `box.ASCII` singleton and then rewrites that singleton in place (`table.box.__dict__.update(...)`, tests/test_table.py line 314) without restoring it. Any test that renders with `box.ASCII` afterwards sees the replacement letters instead of box-drawing characters: ``` python -m pytest tests/test_table.py::test_placement_table_box_elements tests/test_box.py::test_get_row -p no:randomly ``` ``` def test_get_row(): row = ASCII.get_row(widths=[1, 2, 3], level="row") > assert row == "|-+--+---|" E AssertionError: assert 'ijkjjkjjjl' == '|-+--+---|' ``` The suite only stays green because the natural file order happens to run test_box.py before test_table.py. Under pytest-randomly (which the test environment installs) the polluter runs first on roughly half the seeds: in a controlled comparison of 48 shuffled runs against 48 with the plugin disabled, the shuffled runs passed 52% and the natural order 100%, with hash seed, timezone, locale and allocator varied as controls that all stayed quiet. **Proposed fix** Give the table its own copy before mutating, for example `box=copy.deepcopy(box.ASCII)` in the Table constructed by that test, so the shared singleton stays pristine. Happy to send a PR if that direction works for you. **Platform** Reproduced on macOS (arm64), Python 3.13, pytest 9.1.1, pytest-randomly 5.0.0, at master 9d8f9a3. The failure depends only on test order, not on the platform. _Investigated with the help of Claude (Anthropic's Claude Code)._

Comments

ekanshul

Fix is on a fork. Opening a PR is blocked for non-collaborators (`CreatePullRequest`). Compare: https://github.com/Textualize/rich/compare/main...ekanshul:rich:fix/table-box-ascii-copy-4223 `test_placement_table_box_elements` now uses `copy.copy(box.ASCII)` before rewriting box characters, and asserts the shared singleton still has `top_left == "+"`. AI disclosure (AI_POLICY.md): prepared with Cursor Grok 4.6. Happy to adjust if a different approach is preferred.