Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Remove fixture name uniqueness constraint #39

Closed
darrenburns opened this issue Oct 18, 2019 · 1 comment
Closed

Remove fixture name uniqueness constraint #39

darrenburns opened this issue Oct 18, 2019 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@darrenburns
Copy link
Owner

When fixtures are collected, they're stored inside a FixtureRegistry. The FixtureRegistry essentially just wraps a dictionary which maps fixture names to Fixture objects (Dict[str, Fixture]).

class FixtureRegistry:

The name of a Fixture, and therefore the key used to access it from the FixtureRegistry, is just the name of the function. For example, the fixture below has the name bob:

@fixture
def bob():
    return "bob"

A side effect of just using the function name to identify a fixture is that if two fixtures of the same name are collected in a single ward run, the run will fail even if the fixtures are defined in different files (specifically we raise a CollectionError). If we didn't fail the run, the key in the wrapped dict could get overwritten, and we might inject the wrong fixture. Here's where the failure happens:

raise CollectionError(f"Multiple fixtures named '{func.__name__}'.")

  • How should we store fixtures in the registry such that there can be multiple fixtures of the same name across different files?
  • When a test later goes to use a fixture, how will it know which one fixture to get from the registry?
  • Should it only return fixtures that are in sibling modules?
  • How can we make it prioritise fixtures in the same file?
  • Should a warning be printed if a test is unsure which fixture to use?

These are just some of the questions raised by this issue, which will require lots of thought on the most sensible approach.

@darrenburns
Copy link
Owner Author

Ward no longer uses name matching and instead relies on Python's import machinery to find fixtures, so this is no longer a problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant