[pytest-dev] What's the best way of writing tests for terminal width resize behaviour in an assertrepr plugin?
Harry Percival
obeythetestinggoat at gmail.com
Tue Apr 7 14:26:53 EDT 2020
cf discussion here https://github.com/pytest-dev/pytest/issues/162
I'm working on pytest-icdiff, trying to get it to print out well optimised
messages for different terminal sizes, and it's hard.
when i'm running tests using runpytest, and I _think_ in real life too,
config.get_terminal_writer().fullwidth *inside the hook* is returning
incorrect values: resizing the terminal i'm using to run the tests has no
effect on the value i get from it. and when I use that value irl, real
test output does not adjust correctly to the terminal size
but calling py.io.TerminalWriter().fullwidth _outside_ the hook, eg at
module level, _does_ give me readings that look right. but testing that
is hard.
intriguingly, if I do testdir.monkeypatch.setenv('COLUMNS', '50'), then the
fullwdith *inside* the hook varies. but that's no use to me, since IRL
that value doesn't work.
so my question is: a) does anyone know of any good examples of assertrepr
plugins that adjust dynamically to terminal width, and b) what's a good way
of writing tests for that?
here's the repo fwiw
https://github.com/hjwp/pytest-icdiff/blob/master/tests/test_pytest_icdiff.py
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20200407/db761bb4/attachment.html>
More information about the pytest-dev
mailing list