New issue 446: Alternative syntax: allow no-argument fixture functions to be 
used as decorators
https://bitbucket.org/hpk42/pytest/issue/446/alternative-syntax-allow-no-argument

leo-the-manic:

Hi pytest team! I just started using this library a week ago and it is 
fantastic!! I love the detailed test output and the elegant looking test code.

Sorry to gush. Anyway, I am using fixtures I don't need direct access to, in 
exactly the way explained by the docs here: 
http://pytest.org/latest/fixture.html#using-fixtures-from-classes-modules-or-projects

My issue is this: the fixture function itself needs a ``@pytest.fixture`` 
decorator in order to enter the pytest fixture machinery, then to be used 
outside of a funcarg, it must be written in a ``@pytest.mark.usefixtures()`` 
decorator. I find the ``@pytest.mark.usefixtures`` a bit noisy and for some 
reason something about it simply rubs me the wrong way.

My suggestion is to transform functions decorated with ``@pytest.fixture`` into 
decorators themselves so they can mark the functions/classes where they're used.

In other words, turn:

```
#!python
@pytest.mark.usefixtures("cleandir")
def test_cwd_starts_empty(self):
```

into

```
#!python
@cleandir
def test_cwd_starts_empty(self):
```

I am not aware of the technical complexity involved in implementing a syntax 
like this. But if it's possible I think it would be a nice, concise syntax that 
would be much more in line with the funcargs injection style, in terms of 
brevity.

On top of that it would avoid the "stringly-typed" nature of the usefixtures 
function. I am aware that other aspects (e.g. funcargs) are also stringly 
typed, but I still think that letting most linters check the correctness of the 
decorator calls would be at least a minor gain.

Welp, that's all! Thanks for your time =]


_______________________________________________
pytest-commit mailing list
pytest-commit@python.org
https://mail.python.org/mailman/listinfo/pytest-commit

Reply via email to