pytest-dev / pytest-dev/pytest
Support per-request scope for fixtures
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Originally reported by: BitBucket: brettatoms, GitHub: brettatoms
I'm not sure how to really describe this but here's a code sample that demonstrates the issue. Basically if I create a test that takes two fixtures as parameters and one of those fixtures depends on the other fixture then the fixture only gets called once and the test method has the same instance for both fixtures.
import sys
import pytest
class User:
def __init__(self, username, is_admin=False):
self.username = username
self.is_admin = is_admin
@pytest.fixture
def user():
return User('me')
@pytest.fixture
def admin_user(user):
user.username = 'admin'
user.is_admin = True
return user
def test_me(user, admin_user):
print('repr(user): ', repr(user))
print('repr(admin_user): ', repr(admin_user))
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the fixture example in the issue and tracing pytest's fixture dependency and scope handling; no source files or tests are named in the report. Done means a test with user and admin_user receives separate per-request instances while preserving fixture dependency behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100