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

Ability to reusable steps, specifically inside a plugin #754

Closed
kingbuzzman opened this issue Dec 12, 2024 · 4 comments
Closed

Ability to reusable steps, specifically inside a plugin #754

kingbuzzman opened this issue Dec 12, 2024 · 4 comments

Comments

@kingbuzzman
Copy link

Is your feature request related to a problem? Please describe.
Kind of. There is no obvious way to reuse steps from an import. Specifically, I need a straightforward approach to specify at which level these reused steps should be applied. Without this, the process of integrating shared steps across different tests becomes unclear and cumbersome.

Describe the solution you'd like
My current solution, is very nasty, needs a sanity check. Ideally, I'd like a clean, well-structured method that allows me to define and reuse these steps at various levels within my tests, ensuring a more maintainable and understandable codebase.

Describe alternatives you've considered
I’ve experimented with multiple approaches in the codebase, but each attempt has only deepened my confusion. Nothing so far has provided a clear, reliable pattern for managing and reusing these steps effectively.

Additional context
NA


The overarching goal of my project is to establish predefined, shareable test steps that handle mundane operations—such as setting up data, calling a URL, and then verifying data—in a highly explicit and readable manner. This would simplify common testing patterns and promote consistency across projects. For example:

  1. setup data
  2. call url
  3. check data

Rinse and repeat.

@youtux
Copy link
Contributor

youtux commented Dec 12, 2024

what about defining your steps in tests/steps.py, and do from tests.steps import * in the modules you need them?
You can even exploit the pytest fixture definition hierarchy, since functions decorated with @given / @when / @then are actually fixtures under the hood.

For example, you can do from tests.steps.global_steps import * in your main tests/conftest.py, and in child packages of your test suite you can then do more granular imports. E.g. in tests/foo/conftest.py you can do from tests.steps.foo_specific_steps import *

@kingbuzzman
Copy link
Author

@youtux from what i can see

you can do from tests.steps.global_steps import * in your main tests/conftest.py, and in child packages of your test suite you can then do more granular imports. E.g. in tests/foo/conftest.py you can do from tests.steps.foo_specific_steps import *

This does not work, when tests.steps.global_steps get loaded they get set to the namespace global_steps and not conftest. The only way i can get this to work is either

A. copying the code into conftest (yuk)
B. doing my current hack (still yucky)

@The-Compiler
Copy link
Member

Have you tried setting pytest_plugins to make pytest load an additional file from conftest.py? Not sure off-hand whether that works with pytest-bdd too, though.

@youtux
Copy link
Contributor

youtux commented Jan 8, 2025

that's weird, I know of a fairly big codebase that uses the solution described in #754 (comment).

I'll close this unless you can come back with a Minimal, Reproducible Example that shows the issue.

@youtux youtux closed this as completed Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants