allure-csharp icon indicating copy to clipboard operation
allure-csharp copied to clipboard

Невозможно сменить путь конфига в OneTimeSetUp

Open lJFoxl opened this issue 2 years ago • 2 comments

I'm submitting a ...

  • [x] bug report
  • [ ] feature request
  • [ ] support request => Please do not submit support request here, see note at the top of this template.

What is the current behavior?

С версии 2.10 всегда устанавливается либо стандартное значение либо из конфига в базовой директории

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Подробный пример выложил в репозиторий https://github.com/lJFoxl/TempTest

What is the expected behavior?

При установке переменной окружения в OneTimeSetUp конфиг будет соответствовать указанному в path. Environment.SetEnvironmentVariable(AllureConstants.ALLURE_CONFIG_ENV_VARIABLE, path);

What is the motivation / use case for changing the behavior?

Для разделения отчётности по отдельным запускам. В том числе отделение отчётов созданных при отладке.

Please tell us about your environment:

Allure.Net.Commons Version="2.10.0" Allure.NUnit Version="2.10.0" Microsoft.NET.Test.Sdk Version="17.7.2" NUnit Version="3.13.3" NUnit3TestAdapter Version="4.5.0"

Other information

Подробный пример выложил в репозиторий https://github.com/lJFoxl/TempTest запустив тесты с одинаковым кодом мы будем наблюдать ошибку в версии 2.10 и позитивный тест в 2.9.2. Судя по всему AllureLifecycle.Instance вызывается до OneTimeSetUp библиотекой Allure.NUnit

lJFoxl avatar Oct 24 '23 19:10 lJFoxl

Hello, @lJFoxl !

Starting from 2.10 the OneTimeSetUp/OneTimeTearDown methods of a TestFixture are executed in the context of Allure. This is necessary to convert those methods to Allure fixtures as well as to enable using features of Allure (steps, attachments, etc) from them. And as you've just figured out, it's too late to change the config at that point.

Although a more straightforward API for such tasks is indeed necessary, for now, you may just move your code from TestFixture to an assembly-level SetupFixture. See example in this answer.

--

Приветствую, @lJFoxl !

В версии 2.10 методы OneTimeSetUp/OneTimeTearDown тестовых классов выполняются в контексте Allure, чтобы пользователи могли создавать фикстуры в отчёте на их основе и, например, добавлять шаги и аттачменты из них. Allure в этот момент уже проинициализирован, поэтому изменение переменной окружения ALLURE_CONFIG ни на что не влияет.

Переместите ваш код, который отвечает за создание конфига, из тестового класса (TestFixture) в SetUpFixture. Чтобы он точно выполнялся до инициализации Allure, разместите этот класс в пустом пространстве имён. Вот в этом ответе есть пример, а вот по этой ссылке - подробности про SetUpFixture.

delatrie avatar Oct 25 '23 08:10 delatrie

Обновил тестовый пример. https://github.com/lJFoxl/TempTest. Если SetUpFixture находится в подключаемом проекте изменение ALLURE_CONFIG_ENV_VARIABLE ни к чему не приводит, а если в одном проекте то OneTimeSetUp вызывается дважды.

lJFoxl avatar Oct 30 '23 11:10 lJFoxl