Visitar URL original
Improve context manager · Issue #826 · allure-framework/allure-python · GitHub
Skip to content

Improve context manager #826

Description

@danielhoherd

I'm submitting a ...

  • feature request

What is the current behavior?

Context manager for allure.step() does not allow assigning a variable name, which would be useful.

What is the expected behavior?

I'd like it if this worked:

with allure.step('foo') as s:
    print(s.title)

I expected that to work because this does work:

s = allure.step('foo')
print(s.title)

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

Having this named context manager would keep very simple code DRY.

Please tell us about your environment:

  • Allure version: 🤷‍♂️ I'm just doing the code review, not sure how to determine this.
  • Test framework: pytest@^8.2.2
  • Allure adaptor: allure-pytest@^2.13.5

Activity

  1. added theissue type on Apr 1, 2025
  2. danielhoherd commented on Aug 4, 2025

    @danielhoherd
    Author

    @delatrie I was going to open a PR to solve this but when I looked at the python code it looked auto-generated, and I wasn't sure that my changes would be valuable. If you can point me in the right direction I may be able to close this one out. This thing is still bugging me.

    Implementations that I can think of is making a verbose mode for the allure context manager, having an environment variable that turns on verbosity, or exposing the step title as an object in the context manager.

  3. delatrie commented on Aug 4, 2025

    @delatrie
    Contributor

    Hi, @danielhoherd
    Thanks for your willingness to contribute to allure-python.

    There is no generated code here (although some of it is quite old).

    If I understand your feature request correctly, the implementation is just a matter of returning the value from __enter__ here:

    def __enter__(self):
    plugin_manager.hook.start_step(uuid=self.uuid, title=self.title, params=self.params)

    That would be a backward-compatible change, so no feature flag is required.

  4. danielhoherd commented on Aug 11, 2025

    @danielhoherd
    Author

    I heard today that we are going to be moving away from allure, so priority for me to complete this work has disappeared. I still think it's worth doing though because I assume at least some other folks are running into the same issue, but I am not going to have time to do it.

    It's fine with me if this issue is closed as "not planned"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions