-
Notifications
You must be signed in to change notification settings - Fork 102
Adds a dotnet test --logger to invoke Formatter #697
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
base: main
Are you sure you want to change the base?
Conversation
…verts the input to an override to be applied via Environment Variable.
|
This might be viewed as a bit of a hack, as it takes the configuration that the dotnet test command line provides and formats that into an Environment Variable value that then gets passed to Reqnroll and which controls the generation of Messages. It temporarily overrides the existing REQNROLL_FORMATTERS environment variable; and returns its value after test execution. |
|
Did a research: also could not find a generic way to access the output folder (shame...). So I was thinking about this formatter implementation. It could be a pretty good convenience feature. Not so match because of the output folder, but because of convenience on the CI servers, so that you don't need to set environment variables or alter the json config to get a simple html report. But for that, specifying a JSON in the command line is cumbersome. I had the following ideas for the configuration via logger:
I don't think that it is a big problem if you cannot configure multiple formatters via the logger infra, but anyhow we could keep the JSON setting as a backup: Also we could consider also allowing the (The technical implementation with the env var is not necessarily a hack, but probably I would set an internal env var ( What do you think? |
|
Agree on all your points. I like the first option. As an aside, another use for a custom logger would be for us internally. We often struggle to log the internal operation of Reqnroll and to keep such log content separate from the content of the test execution. If we generalized the concept of the IFormatterLog and sent that content only to a custom --Logger, that would provide us a convenient way to log internal execution state. |
|
Another thought- I agree that the logger should set a distinct environment variable. In other words we might have one message sink configured via json file and another configured via command line? I could see a configuration provider that watches for the special environment variable and then adds a new instance of the formatter to the global container. As long as this happens early enough in the startup sequence it would work. |
I think this should be additive/overwrite:
The interesting situation is, what should be the result, if I have x.html configured in JSON (that means bin/Debug/net9.0/x.html), but would "enable" is also from the logger, but without an output file, then it should be
I think we should go for 1). That is the easiest anyway, and the use-case is pretty much artificial. |
Let's clarify our rules and order of precedence.
One way to implement the above is to treat the path and filename as independent settings that have recognized default values and those values may be overridden. {Path default: '.', Filename default: 'reqnroll_report.ext'} Questions: |
Let's separate this two questions (individually configurable formatters; separation of output folder and output file) and let's concentrate on the "individually configurable formatters" in this PR. So for now let's keep the single So my revised list:
This would be nice IMHO if not much work.
If we could do A) then this one would be also nice.
Let's not deal with this now, see above.
I don't understand this question. |
…now uses key-value pairs, such as --logger "formatter;name=message;outputFilePath=foo.ndjson". The infrastructure is now in place to set multiple loggers on the command line, but that is not yet working.
|
I've adopted your comments and have it almost working correctly. How would you like to proceed? Options:
|
…derive from a base class.
|
As the first portion of refactoring this, commit f99c7d3 creates two named loggers (one for messages and one for html). If you prefer the names reversed (such as I'll next add another more generic formatter logger (will call it |
|
@gasparnagy I've tried to create a --logger that would accept a general json config element and I'm failing. I can't get the quote escaping correct. Powershell and/or the dotnet test infrastructure seem to strip out all quotes from the command line parameter and I'm left with a string that I can't pass to the Formatter configuration subsystem. I don't have confidence that I could parse this string and reconstruct a proper json representation of it (as its supposed to be general, we can't predict what other plugin formatters may want as configuration input). So far, I've tried:
I'm open to suggestions of things to try. Any ideas? |
|
@clrudolphi sorry for not responding earlier.
This is great! I like it.
I see the problem. Not easy. Probable the reverse name would be better though.
I have also tried that once (other project), but running into the same issues. I think this is not feasible, because others will suffer from the same problems. My suggestion is the following: The generic one should be called "formatter" (singular) and should only allow configuring a single formatter, in a form |
No problem at all. I'll make that change.
The whole point, really, of the generic logger was to support plugin formatters. IMO, we have sufficient mechanisms for the built-in ones. Therefore, IMO, we drop the idea for now. I'll make the adjustment to the named formatter loggers and then we're done. |
|
Before we merge this, I'll edit the docs to include the logger configuration of the formatters. Edit: I put the revised docs into the page that describes other loggers. There is no merge conflict with the Formatters documentation page. |
Added description of how to configure the formatters using the --logger command line.
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="17.14.1" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question:
Does this also work with the new Microsoft.Testing.Platform?
Do we need a test for both (vstest and Microsoft.Testing.Platform)?
For reference see discussions in Tyrrrz/GitHubActionsTestLogger#41.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh. No good deed goes unpunished.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. I have checked the linked article, and based on that we should strongly consider if we want to have this logger support included. It is not essential for us and it is declared to be slowly deprecated.
Later we can think about having an MTP reporter.
🤔 What's changed?
This PR adds a custom vstest infrastructure logger that can be used via the command line to configure Formatters.
It will pick up and use the TestResults folder if one is not explicitly specified.
ex:
⚡️ What's your motivation?
This does get us access to the TestResults path which otherwise isn't easily available.
🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
Anything.
📋 Checklist:
This text was originally taken from the template of the Cucumber project, then edited by hand. You can modify the template here.