-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] How to test output of rich.Table? #247
Comments
The easiest way to capture output from rich is to set the file to a StringIO. Something like this: console = Console(file=io.StringIO(), width=120)
console.print(table)
output = console.file.getvalue() You could also test the attributes of the Table object directly. e.g. |
I see that looks good, thanks for the quick reply. |
another way - https://rich.readthedocs.io/en/stable/reference/console.html#rich.console.Console.export_text
it will be printed in console and saved in variable |
@timothygebhard thanks |
@willmcgugan that's works. But how to print to file a table with a color info? |
@willmcgugan Ok. Thanks. At the end I was able to do this, so I called it a success :) |
Hey, first thanks for this awesome package.
I have a small question on how to test for output of a rich
Table
, assume I have the following code:Now while testing this (with different values for
myproject
) using pytest I'd like to check if this table meets some requirements (so I'd like to check for example if the title is right).How would one do this?
My naive approach was just to capture the output with pytest (basically a big string) a test whether it contains my desired title. However this does not work, as the output is something like:
So TL;DR: Is there any nice way to test the output of a table? Thanks in advance ;)
The text was updated successfully, but these errors were encountered: