You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow an argument to match a type formatter by its interface/base class/generic definition #644
The type formatters API allows users to provide their own serialization algorithms to format arguments of certain types. To do so, two things are required:
Define a class that derives from Allure.Net.Commons.TypeFormatter<T>.
Call Allure.Net.Commons.AllureLifecycle.AddTypeFormatter<T>(Allure.Net.Commons.TypeFormatter<T> formatter) early enough for the formatter to be picked up by Allure.
If everything is done right, Allure will use the formatter to convert arguments of the matched type to strings in two contexts:
when converting test method arguments to strings (usually, at test end)
when convertins arguments of attribute-based steps at step end
Limitations
If we'd like to format a value of type T, then:
T must be known at compile time
T must be accessible
T must be the exact type of the value (i.e., value.GetType() == typeof(T) must be true)
This is cumbersome in the following situations:
T is a private or internal type of a 3rd party library
There are a lot of types we'd like to format similarly but have to call AddTypeFormater for each of them anyway.
Solution
A solution is to make the matching algorithm less restrictive. We can try to find a match in the following order:
TypeFormatter<T>.
TypeFormatter<G>, where G is a generic type definition of a (bound) generic type T.
TypeFormatter<I>, where I is a type of an interface implemented by T.
TypeFormatter<IG>, where IG is a generic type definition of an interface implemented by T.
TypeFormatter<B>, where B is a base class of T.
TypeFormatter<GB>, where GB is a generic type definition of the base class of T.
Options 2, 4, and 6 require a new AddTypeFormatter overload since these formatters can't be added with the existing one.
Options 5 and 6 apply repeatedly until we reach System.Object.
If the match result is found, we can cache it by adding the [value.GetType(), formatter] entry to the dictionary of formatters.
This would be very useful for us too. I was about to raise a separate enhancement before finding this issue.
Minimal Repro
using System;
using Allure.Net.Commons;
using Allure.NUnit.Attributes;
using NUnit.Framework;
public class Repro
{
[AllureStep("Run noisy step")]
public void Run(Action callback)
{
callback();
}
[Test]
public void ShowsHugeParameterPayload()
{
Run(() => { });
}
}
Observed:
callback parameter is extremely large (delegate internals / runtime object graph)
Expected:
Ability to define a global/fallback formatter for unmatched types, e.g. "" or truncated text
Why this matters:
Without assignable/fallback matching, consumers need reflection-heavy custom code to discover concrete runtime types and register formatters one-by-one.
Activity
Riverlution commentedon Feb 23, 2026
This would be very useful for us too. I was about to raise a separate enhancement before finding this issue.
Minimal Repro
Observed:
Expected:
Why this matters:
Allow type formatters to match by interface, base class, and generic …
Allow type formatters to match by interface, base class, and generic …
NoTh0ughts commentedon Jul 28, 2026
As a workaround, you can override
JsonConvert.DefaultSettingslocally in OneTimeSetup with useful fields such asMaxDepthandConverters.