Set Allure-Result directory #2154
-
Hi I'm trying to make folders with test-results for every time my tests are executed. For example: Want to have the results as:
I'm using C# with NUnit, tried to modify AllureLifeCycle.Instance.ResultDirectory but seems that its a readonly attribute thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello, @ZhouZhengCarlos! Changing the configuration at runtime is not possible at the moment. What you can do instead is to create the configuration file you need before the tests start executing and point the I advise you to use an assembly-level SetUpFixture for such a task (i.e., a SetUpFixture with no namespace) to be sure it affects all tests in the assembly. The following should do the trick: using System.Text;
using System.Text.Json;
using Allure.Net.Commons;
using NUnit.Framework;
[SetUpFixture]
class PrepareOutputDirectoryFixture
{
string? path;
[OneTimeSetUp]
public void SetOutputDirectory()
{
this.path = Path.GetTempFileName();
var directory = Directory.CreateDirectory(
Path.Combine(
GetCurrentAllureDirectory(),
CreateSubfolderName()
)
);
File.WriteAllText(
this.path,
JsonSerializer.Serialize(
new { allure = new { directory = directory.FullName } }
),
Encoding.UTF8
);
Environment.SetEnvironmentVariable(AllureConstants.ALLURE_CONFIG_ENV_VARIABLE, this.path);
}
[OneTimeTearDown]
public void DeleteTempConfigFile()
{
Environment.SetEnvironmentVariable(AllureConstants.ALLURE_CONFIG_ENV_VARIABLE, null);
if (this.path is not null && File.Exists(this.path))
{
File.Delete(this.path);
}
}
static string GetCurrentAllureDirectory() => "allure-results";
static string CreateSubfolderName() => DateTime.Now.ToString("yy-MM-dd");
} Just place your logic to get the parent folder and the name of the subfolder in Note, however, that if you already have an existing allureConfig.json, you will need to modify the code to combine that with the one you craft in the fixture. I didn't include that logic for the sake of simplicity. You also may get the same result using a well-crafted shell script or msbuild task, although it might be even more tricky if you have more than one test assembly. |
Beta Was this translation helpful? Give feedback.
Hello, @ZhouZhengCarlos!
Changing the configuration at runtime is not possible at the moment. What you can do instead is to create the configuration file you need before the tests start executing and point the
ALLURE_CONFIG
env variable to it. If you do that early enough, Allure will pick the config you've just crafted and use it.I advise you to use an assembly-level SetUpFixture for such a task (i.e., a SetUpFixture with no namespace) to be sure it affects all tests in the assembly. The following should do the trick: