-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Move rule characters into class attributes of TerminalReporter #7647
Conversation
…es of TerminalReporter. This allows those characters to be replaced by plugins (i.e. with Unicode box drawing characters) and documents which characters are used.
Thanks for splitting this! A couple of questions to start with:
|
I can imagine all of those variants.
I think for simple customizations replacing the characters (either directly or by overrwriting the attributes in a subclasses) is the way to go. But I can imagine bars that are done by using a different background color or by drawing a frame around the title. For this overwriting the method would be necessary. But then the question becomes whether |
Indeed, that was my understanding as well.
Those are good points. To me the |
OK, then |
|
Nice idea. But I'm not sure what the return value of type And if I'm no longer sure if |
To return the int from https://docs.python.org/3/library/io.html#io.TextIOBase.write |
Ah, OK. Currently none of the |
I like @graingert do you see a use case for returning an int from that method? |
Ok |
Now the question remains whether |
Not sure either way. Would like to hear @bluetech's opinion before moving further into the discussion however. |
My concern is that this adds a way to customize For a library like pytest, we need to be careful about public interfaces and the stability guarantees we make for them. For a class like like SubclassingIn practice it means writing a class which inherits from Currently, Also, MonkeypatchingIn practice it means obtaining the Similarly to subclassing, if we want to sanction this method, we need to clearly document which attributes are monkeypatchable, and make them convenient and stable. To me this seems not very elegant, I think plugin authors would prefer other methods, and regular users are very unlikely to do it on their own. Also, it is mostly limited to overriding simple attributes, suggesting to monkeypatching methods I think is too much. So this approach is less flexible. HooksThis is the official sanctioned method that pytest offers for customizing things. It is stable and well-defined. Of course, So the more practical thing is to have |
Regarding the more specific discussion:
Generally more customization points mean more mental and maintenance overhead, so my preference would be to stick to one level, unless they are aimed at different audiences (e.g. plugins and users). If the method is more general and just as viable, I would provide only that.
I don't have a detailed opinion but I do prefer the the names to be as semantic as possible instead of |
@bluetech you are definitely right in your points here. The current situation is that pytest output is not really customizable, so plugins that try to customize it usually fallback to subclassing As you say, hooks is the way to go method for customization in pytest and there are already hooks dedicated to customize terminal output, so we might consider that approach indeed. If we go with hooks, I don't see a clear way to customize the actual writing of the separators (as one would with subclassing and writing their own routine), only the characters used to draw the separators, similar to what we have with def pytest_terminal_separators(config: Config) -> Dict[str, str]:
... Which would return the separators used to draw each "level", for example the default would be: {
"heading_1": "=",
"heading_2": "-",
"heading_3": "_",
"error": "!",
} |
But this version wouldn't allow doing something fancier. Why can't the hook do it's own drawing? Because this would have to callback into some basic drawing functionality? |
That's a possibility indeed; in fact we already have a hook that does provide the def pytest_terminal_summary(
terminalreporter: "TerminalReporter", exitstatus: "ExitCode", config: "Config",
) -> None: |
As per the discussion above, this feature would need some more design work, so I'll close this PR. Thanks @doerwalter. |
Move characters used for drawing horizontal rules into class attributes of
TerminalReporter
.This allows those characters to be replaced by plugins (i.e. with Unicode box drawing characters) and documents which characters are used.