February 13, 2016

Your Very Own Pytest Decorators

  —How to create your own PyTest decorators.

I was exploring Pytest to discover a way to add a decorator to my test cases. I went with a solution using pytest_namespace().

In conftest.py:

1
2
3
4
5
6
7
8
9
def decorator(func):
def _decorator():
func()
return _decorator

def pytest_namespace():
return {
'decorator': decorator
}

A source file:
1
2
3
@pytest.decorator
def test_decorator():
pass

Simple.

Gist
comments powered by Disqus