Skip to content

Commit

Permalink
introduce attrs as dependency
Browse files Browse the repository at this point in the history
as a initial class to use it i picked FixtureFunctionMarker and made it immutable
  • Loading branch information
RonnyPfannschmidt committed Aug 1, 2017
1 parent 6e75472 commit b2f2d76
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
24 changes: 16 additions & 8 deletions _pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import warnings

import inspect
import attr
import _pytest
from _pytest._code.code import TerminalRepr
from _pytest.compat import (
Expand Down Expand Up @@ -611,7 +612,6 @@ def scope2index(scope, descr, where=None):
scope)
)


class FixtureLookupError(LookupError):
""" could not return a requested Fixture (missing or invalid). """

Expand Down Expand Up @@ -823,13 +823,21 @@ def pytest_fixture_setup(fixturedef, request):
return result


class FixtureFunctionMarker:
def __init__(self, scope, params, autouse=False, ids=None, name=None):
self.scope = scope
self.params = params
self.autouse = autouse
self.ids = ids
self.name = name
def _ensure_immutable_ids(ids):
if ids is None:
return
if callable(ids):
return ids
return tuple(ids)


@attr.s(frozen=True)
class FixtureFunctionMarker(object):
scope = attr.ib()
params = attr.ib(convert=attr.converters.optional(tuple))
autouse = attr.ib(default=False)
ids = attr.ib(default=None, convert=_ensure_immutable_ids)
name = attr.ib(default=None)

def __call__(self, function):
if isclass(function):
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ def has_environment_marker_support():


def main():
install_requires = ['py>=1.4.33', 'setuptools'] # pluggy is vendored in _pytest.vendored_packages
install_requires = [
'py>=1.4.33',
'setuptools',
'attrs',
] # pluggy is vendored in _pytest.vendored_packages
extras_require = {}
if has_environment_marker_support():
extras_require[':python_version=="2.6"'] = ['argparse', 'ordereddict']
Expand Down

0 comments on commit b2f2d76

Please sign in to comment.