Skip to content
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

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

Open
1 of 3 tasks
lJFoxl opened this issue Oct 24, 2023 · 2 comments
Open
1 of 3 tasks

Comments

@lJFoxl
Copy link

lJFoxl commented Oct 24, 2023

I'm submitting a ...

  • 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 lJFoxl changed the title Не возможно сменить путь конфига в OneTimeSetUp Невозможно сменить путь конфига в OneTimeSetUp Oct 24, 2023
@delatrie
Copy link
Contributor

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.

@lJFoxl
Copy link
Author

lJFoxl commented Oct 30, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants