wemake-services / wemake-services/wemake-python-styleguide

Make sure we treat tests differently

Open
#1,120 17 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature help wanted level:advanced
Dominant language
Python
Stars
2.9k
Forks
430
Avg merge
5h 14m
Merged PRs (30d)
34

Description

When using pytest fixtures, you are supposed to just declare them as input arguments, and they will be automagically loaded. For example:

import pytest
from myapp import meaning_of_life


@pytest.fixture
def foo():
    return 42

def test_meaning_of_life(foo):
    meaning = meaning_of_life()
    assert meaning == foo

This will violate rule 442, which is not desired in this case.

One could argue that fixtures should live on a different file than tests, but you run on the same issue if you have fixtures dependent on other fixtures:

import pytest


@pytest.fixture
def foo():
    return 42


@pytest.fixture
def bar(foo):
    return foo + 1

I think we need to make this feature "pytest aware", or just document that it there is conflict with it and might need to be disabled.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names rule 442 but no source file or test path. Start by locating rule 442's implementation and existing tests, then reproduce the two pytest fixture examples. Done requires an agreed behavior for fixture arguments, either pytest-aware handling or explicit documentation of the conflict.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.