Skip to content

Commit

Permalink
Use new pytest mark API
Browse files Browse the repository at this point in the history
Process each mark separately, rather than relying on automatic merging
of args and kwargs.

See https://docs.pytest.org/en/latest/mark.html#updating-code

This requires pytest 3.6, which does not run on python 2.6. Travis
environments have pytest 3.4 installed by default; this needs to be
explicitly updated.

Fixes #2
  • Loading branch information
tomjnixon committed Sep 13, 2018
1 parent f8c996c commit 82b7411
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -2,14 +2,14 @@

language: python
python:
- 2.6
- 2.7
- 3.4
- 3.5
- 3.6
- pypy

install:
- pip install --upgrade pytest
- pip install coveralls

script:
Expand Down
12 changes: 8 additions & 4 deletions pytest_datafiles.py
Expand Up @@ -66,16 +66,20 @@ def datafiles(request, tmpdir):
pytest fixture to define a 'tmpdir' containing files or directories
specified with a 'datafiles' mark.
"""
if 'datafiles' not in request.keywords:
return tmpdir
content = request.keywords.get('datafiles').args
content = []
options = {
'keep_top_dir': False,
'on_duplicate': 'exception', # ignore, overwrite
}
options.update(request.keywords.get('datafiles').kwargs)
for mark in request.node.iter_markers('datafiles'):
content.extend(mark.args)
options.update(mark.kwargs)
on_duplicate = options['on_duplicate']
keep_top_dir = options['keep_top_dir']

if not content:
return tmpdir

if keep_top_dir not in (True, False):
raise ValueError("'keep_top_dir' must be True or False")
if on_duplicate not in ('exception', 'ignore', 'overwrite'):
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Expand Up @@ -13,7 +13,7 @@ def _read(fname):

DEPENDENCIES = [
'py',
'pytest',
'pytest>=3.6',
]

DESCRIPTION = ("py.test plugin to create a 'tmpdir' containing predefined "
Expand Down Expand Up @@ -43,7 +43,6 @@ def _read(fname):
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py26, py27, py34, py35, py36
envlist = py27, py34, py35, py36

[testenv]
commands = py.test tests/test_pytest_datafiles.py
Expand Down

0 comments on commit 82b7411

Please sign in to comment.