Skip to content

Conversation

delatrie
Copy link
Contributor

@delatrie delatrie commented Oct 13, 2025

Context

Currently, if Allure is not running, attempting to call functions from AllureApi or ExtendedApi or a function marked with [AllureStep], [AllureBefore], or [AllureAfter] leads to InvalidOperationException with a somewhat cryptic message about Allure context. This makes it challenging to selectively disable Allure in some environments (e.g., on a developer's machine) while enabling it in others (like a CI workflow).

This PR makes all those functions and attributes usable in such scenarios. Now, they check the Allure context first. If it doesn't allow the function to do its job, the function becomes a noop:

  • Functions that add/set metadata do nothing and exit (SetTestName, AddLabel, etc).
  • Lambda step/fixture functions call the functions they wrap and return the result. They don't do anything else.
  • Step/fixture attributes also call their target functions directly and do nothing more. In particular, they don't attempt to format the arguments, which saves performance.

Closes #445

Checklist

@delatrie delatrie added the task:improvement Change that improves some user experience but can't be considered a new feature label Oct 13, 2025
@delatrie delatrie added type:improvement and removed task:improvement Change that improves some user experience but can't be considered a new feature labels Oct 13, 2025
@delatrie delatrie merged commit 9008372 into main Oct 13, 2025
8 of 9 checks passed
@delatrie delatrie deleted the fix/issue-445-allure-api-exceptions branch October 13, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InvalidOperationException when calling a function from AllureApi and ExtendedApi outside the Allure context

2 participants