Skip to content

Commit e7ac943

Browse files
committed
Merge pull request #31 from alexamici/master
Big option rename. Closes #30.
2 parents 513ed4c + 06160ec commit e7ac943

File tree

12 files changed

+117
-111
lines changed

12 files changed

+117
-111
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
0.9.8 (unreleased)
33
------------------
44

5-
- Add the `pytest.mark.target` marker in the place of `pytest_nodev.search`.
5+
- Add the ``pytest.mark.candidate`` marker in the place of ``pytest_nodev.search``.
66
Issue `#28 <https://github.com/nodev-io/pytest-nodev/issues/28>`_.
7+
- Rename main fixture to ``candidate`` from ``wish``.
8+
Issue `#30 <https://github.com/nodev-io/pytest-nodev/issues/30>`_.
9+
So long, and thanks for all the fish.
710

811

912
0.9.7 (2016-03-13)
@@ -47,7 +50,7 @@
4750
0.9.2 (2016-02-20)
4851
------------------
4952

50-
- Disable potentially dangerous ``--wish-from-all`` by default.
53+
- Disable potentially dangerous ``--candidates-from-all`` by default.
5154

5255

5356
0.9.1 (2016-02-16)

CONTRIBUTING.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ along with a detailed description.
1515
Submit a pull request
1616
---------------------
1717

18+
Contributors are invited to review the
19+
`product high level design <https://pytest-nodev.readthedocs.org/en/stable/design.html>`_
20+
and the `short term planning <https://github.com/nodev-io/pytest-nodev/milestones>`_.
21+
1822
Tests can be run with `pytest <https://pytest.org>`_ and `tox <https://tox.readthedocs.org>`_,
1923
please ensure the coverage at least stays the same before you submit a pull request.

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ COPY . /src
1212
WORKDIR /src
1313

1414
# setup the python and pytest environments
15+
RUN pip install --upgrade pip setuptools
1516
RUN pip install --upgrade -r requirements.txt
1617
RUN pip install --upgrade -r requirements-tests.txt
1718
RUN pip install -e .

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ decorate it with ``pytest.mark.target`` as follows::
6060

6161
Finally, instruct pytest to run your test on all functions in the Python standard library::
6262

63-
$ py.test test_parse_bool.py --wish-from-stdlib
63+
$ py.test test_parse_bool.py --candidates-from-stdlib
6464
======================= test session starts ==========================
6565
platform darwin -- Python 3.5.0, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
6666
rootdir: /tmp, inifile: setup.cfg
@@ -103,7 +103,7 @@ BIG FAT WARNING!
103103
A lot of functions called with the wrong set of arguments may have unexpected consequences ranging
104104
from slightly annoying, think ``os.mkdir('false')``,
105105
to **utterly catastrophic**, think ``shutil.rmtree('/', True)``.
106-
Serious use of pytest-nodev, in particular using ``--wish-from-all``,
106+
Serious use of pytest-nodev, in particular using ``--candidates-from-all``,
107107
require running the tests with operating-system level isolation,
108108
e.g. as a dedicated user or even better inside a dedicated container.
109109
The `User's guide <http://pytest-nodev.readthedocs.org/en/stable/usersguide.html>`_

docs/design.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ No completeness and no performance guarantees.
5656

5757
- Search environment definition:
5858

59-
- Support defining which modules to search. Command line ``--wish-from-*`` options.
59+
- Support defining which modules to search. Command line ``--candidates-from-*`` options.
6060

6161
- Support defining which objects to include/exclude by name or via a predicate test function.
62-
Command line ``--wish-includes/excludes/predicate`` options.
62+
Command line ``--candidates-includes/excludes/predicate`` options.
6363

6464
- Object collection:
6565

6666
- Collect most objects from the defined environment. It is ok to miss some objects for now.
6767

6868
- Test execution:
6969

70-
- Execute tests instrumented with the ``wish`` fixture once for every object collected.
71-
The tests are marked ``xfail`` unless the ``--wish-fail`` command line option is given to
70+
- Execute tests instrumented with the ``candidate`` fixture once for every object collected.
71+
The tests are marked ``xfail`` unless the ``--candidates-fail`` command line option is given to
7272
make standard pytest reporting the most useful.
7373

7474
- Report:
@@ -83,9 +83,9 @@ No completeness and no performance guarantees.
8383

8484
- Potentially dangerous, crashing, hard hanging or simply annoying objects
8585
belonging to the standard library are unconditionally blacklisted
86-
so that new users can test ``--wish-from-stdlib`` without bothering with OS-level isolation.
86+
so that new users can test ``--candidates-from-stdlib`` without bothering with OS-level isolation.
8787

88-
- Limited use of ``--wish-from-all``.
88+
- Limited use of ``--candidates-from-all``.
8989

9090
- Documentation:
9191

docs/usersguide.rst

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ from the Python Package Index::
1818
Basic usage
1919
-----------
2020

21-
Write a specification test instrumented with the ``wish`` fixture in the ``test_example.py`` file.
22-
Run pytest with one of the ``--wish-from-*`` options to select the search space,
21+
Write a specification test instrumented with the ``candidate`` fixture in the ``test_example.py`` file.
22+
Run pytest with one of the ``--candidates-from-*`` options to select the search space,
2323
e.g. to search in the Python standard library::
2424

25-
$ py.test --wish-from-stdlib test_example.py
25+
$ py.test --candidates-from-stdlib test_example.py
2626

2727

2828
Advanced usage
2929
--------------
3030

31-
Use of ``--wish-from-all`` may be very dangerous
31+
Use of ``--candidates-from-all`` may be very dangerous
3232
and it is disabled by default.
3333

3434
In order to search safely in all modules we suggest to use docker for OS-level isolation.
@@ -43,40 +43,41 @@ build the nodev docker image with all module from requirements.txt installed::
4343

4444
and run tests with::
4545

46-
$ docker run --rm -it -v `pwd`:/home/pytest nodev --wish-from-all tests/test_factorial.py
46+
$ docker run --rm -it -v `pwd`:/home/pytest nodev --candidates-from-all tests/test_factorial.py
4747

4848
Alternatively you can enable it on your regular user only after you have understood the risks
4949
and set up appropriate mitigation strategies
5050
by setting the ``PYTEST_NODEV_MODE`` environment variable to ``FEARLESS``::
5151

52-
$ PYTEST_NODEV_MODE=FEARLESS py.test --wish-from-all --wish-includes .*util -- test_example.py
52+
$ PYTEST_NODEV_MODE=FEARLESS py.test --candidates-from-all --candidates-includes .*util -- test_example.py
5353

5454

5555
Command line reference
5656
----------------------
5757

5858
The plugin adds the following options to pytest command line::
5959

60-
wish:
61-
--wish-from-stdlib Collects objects form the Python standard library.
62-
--wish-from-all Collects objects form the Python standard library and
63-
all installed packages. Disabled by default, see the
64-
docs.
65-
--wish-from-specs=WISH_FROM_SPECS=[WISH_FROM_SPECS=...]
66-
Collects objects from installed packages. Space
60+
nodev:
61+
--candidates-from-stdlib
62+
Collects candidates form the Python standard library.
63+
--candidates-from-all
64+
Collects candidates form the Python standard library
65+
and all installed packages. Disabled by default, see
66+
the docs.
67+
--candidates-from-specs=CANDIDATES_FROM_SPECS=[CANDIDATES_FROM_SPECS=...]
68+
Collects candidates from installed packages. Space
6769
separated list of `pip` specs.
68-
--wish-from-modules=WISH_FROM_MODULES=[WISH_FROM_MODULES=...]
69-
Collects objects from installed modules. Space
70+
--candidates-from-modules=CANDIDATES_FROM_MODULES=[CANDIDATES_FROM_MODULES=...]
71+
Collects candidates from installed modules. Space
7072
separated list of module names.
71-
--wish-includes=WISH_INCLUDES=[WISH_INCLUDES=...]
73+
--candidates-includes=CANDIDATES_INCLUDES=[CANDIDATES_INCLUDES=...]
7274
Space separated list of regexs matching full object
7375
names to include, defaults to include all objects
74-
collected via `--wish-from-*`.
75-
--wish-excludes=WISH_EXCLUDES=[WISH_EXCLUDES=...]
76+
collected via `--candidates-from-*`.
77+
--candidates-excludes=CANDIDATES_EXCLUDES=[CANDIDATES_EXCLUDES=...]
7678
Space separated list of regexs matching full object
7779
names to exclude.
78-
--wish-predicate=WISH_PREDICATE
80+
--candidates-predicate=CANDIDATES_PREDICATE
7981
Full name of the predicate passed to
8082
`inspect.getmembers`, defaults to `builtins.callable`.
81-
--wish-fail Show wish failures.
82-
83+
--candidates-fail Show candidates failures.

pytest_nodev/blacklists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
2626
Potentially dangerous, crashing, hard hanging or simply annoying objects
2727
belonging to the standard library and to and the pytest-nodev dependencies
28-
are unconditionally blacklisted so that new users can test ``--wish-from-stdlib``
28+
are unconditionally blacklisted so that new users can test ``--candidates-from-stdlib``
2929
without bothering with OS-level isolation.
3030
"""
3131

pytest_nodev/collect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
MODULE_BLACKLIST_PATTERN = '|'.join(blacklists.MODULE_BLACKLIST) or NOMATCH_PATTERN
4949
OBJECT_BLACKLIST_PATTERN = '|'.join(blacklists.OBJECT_BLACKLIST) or NOMATCH_PATTERN
5050

51-
logger = logging.getLogger('wish')
51+
logger = logging.getLogger('nodev')
5252

5353

5454
def recurse_import_path(path=None, prefix='', spec='UNKOWN'):

pytest_nodev/plugin.py

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,39 +38,39 @@
3838

3939

4040
def pytest_addoption(parser):
41-
group = parser.getgroup('wish')
41+
group = parser.getgroup('nodev')
4242
group.addoption(
43-
'--wish-from-stdlib', action='store_true',
44-
help="Collects objects form the Python standard library.")
43+
'--candidates-from-stdlib', action='store_true',
44+
help="Collects candidates form the Python standard library.")
4545
group.addoption(
46-
'--wish-from-all', action='store_true',
47-
help="Collects objects form the Python standard library and all installed packages. "
46+
'--candidates-from-all', action='store_true',
47+
help="Collects candidates form the Python standard library and all installed packages. "
4848
"Disabled by default, see the docs.")
4949
group.addoption(
50-
'--wish-from-specs', default=[], nargs='+',
51-
help="Collects objects from installed packages. Space separated list of `pip` specs.")
50+
'--candidates-from-specs', default=[], nargs='+',
51+
help="Collects candidates from installed packages. Space separated list of `pip` specs.")
5252
group.addoption(
53-
'--wish-from-modules', default=[], nargs='+',
54-
help="Collects objects from installed modules. Space separated list of module names.")
53+
'--candidates-from-modules', default=[], nargs='+',
54+
help="Collects candidates from installed modules. Space separated list of module names.")
5555
group.addoption(
56-
'--wish-includes', nargs='+',
56+
'--candidates-includes', nargs='+',
5757
help="Space separated list of regexs matching full object names to include, "
58-
"defaults to include all objects collected via `--wish-from-*`.")
58+
"defaults to include all objects collected via `--candidates-from-*`.")
5959
group.addoption(
60-
'--wish-excludes', default=[], nargs='+',
60+
'--candidates-excludes', default=[], nargs='+',
6161
help="Space separated list of regexs matching full object names to exclude.")
6262
group.addoption(
63-
'--wish-predicate', default='builtins:callable',
63+
'--candidates-predicate', default='builtins:callable',
6464
help="Full name of the predicate passed to `inspect.getmembers`, "
6565
"defaults to `builtins.callable`.")
66-
group.addoption('--wish-fail', action='store_true', help="Show wish failures.")
66+
group.addoption('--candidates-fail', action='store_true', help="Show candidates failures.")
6767

6868

69-
def make_wish_index(config):
70-
if config.getoption('wish_from_all') and os.environ.get('PYTEST_NODEV_MODE') != 'FEARLESS':
71-
raise ValueError("Use of --wish-from-all may be very dangerous, see the docs.")
69+
def make_candidate_index(config):
70+
if config.getoption('candidates_from_all') and os.environ.get('PYTEST_NODEV_MODE') != 'FEARLESS':
71+
raise ValueError("Use of --candidates-from-all may be very dangerous, see the docs.")
7272

73-
if not hasattr(config, '_wish_index_items'):
73+
if not hasattr(config, '_candicate_index'):
7474
# take over collect logging
7575
collect.logger.propagate = False
7676
collect.logger.setLevel(logging.DEBUG) # FIXME: loglevel should be configurable
@@ -82,70 +82,69 @@ def make_wish_index(config):
8282
# build the object index
8383
distributions = collections.OrderedDict()
8484

85-
if config.getoption('wish_from_stdlib') or config.getoption('wish_from_all'):
85+
if config.getoption('candidates_from_stdlib') or config.getoption('candidates_from_all'):
8686
distributions.update(collect.collect_stdlib_distributions())
8787

88-
if config.getoption('wish_from_all'):
88+
if config.getoption('candidates_from_all'):
8989
distributions.update(collect.collect_installed_distributions())
9090

91-
distributions.update(collect.collect_distributions(config.getoption('wish_from_specs')))
91+
distributions.update(collect.collect_distributions(config.getoption('candidates_from_specs')))
9292

93-
if config.getoption('wish_from_modules'):
94-
distributions['unknown distribution'] = config.getoption('wish_from_modules')
93+
if config.getoption('candidates_from_modules'):
94+
distributions['unknown distribution'] = config.getoption('candidates_from_modules')
9595

9696
top_level_modules = collect.import_distributions(distributions.items())
9797

98-
includes = config.getoption('wish_includes')
98+
includes = config.getoption('candidates_includes')
9999
if not includes:
100-
includes = ['.'] if config.getoption('wish_from_all') else sorted(top_level_modules)
101-
excludes = config.getoption('wish_excludes')
102-
predicate = config.getoption('wish_predicate')
100+
includes = ['.'] if config.getoption('candidates_from_all') else sorted(top_level_modules)
101+
excludes = config.getoption('candidates_excludes')
102+
predicate = config.getoption('candidates_predicate')
103103

104104
# NOTE: 'copy' is needed here because indexing may unexpectedly trigger a module load
105105
modules = sys.modules.copy()
106106
object_index = dict(
107-
collect.generate_objects_from_modules(modules, includes, excludes,
108-
predicate)
107+
collect.generate_objects_from_modules(modules, includes, excludes, predicate)
109108
)
110109

111110
# store index
112-
config._wish_index_items = list(zip(*sorted(object_index.items()))) or [(), ()]
111+
config._candicate_index = list(zip(*sorted(object_index.items()))) or [(), ()]
113112

114-
return config._wish_index_items
113+
return config._candicate_index
115114

116115

117116
def pytest_pycollect_makeitem(collector, name, obj):
118-
target_marker = getattr(obj, 'target', None)
119-
if target_marker and getattr(target_marker, 'args', []):
120-
target_name = target_marker.args[0]
117+
candidate_marker = getattr(obj, 'candidate', None)
118+
if candidate_marker and getattr(candidate_marker, 'args', []):
119+
candidate_name = candidate_marker.args[0]
121120

122-
def wrapper(wish, monkeypatch, *args, **kwargs):
123-
if '.' in target_name:
124-
monkeypatch.setattr(target_name, wish, raising=False)
121+
def wrapper(candidate, monkeypatch, *args, **kwargs):
122+
if '.' in candidate_name:
123+
monkeypatch.setattr(candidate_name, candidate, raising=False)
125124
else:
126-
monkeypatch.setattr(inspect.getmodule(obj), target_name, wish, raising=False)
125+
monkeypatch.setattr(inspect.getmodule(obj), candidate_name, candidate, raising=False)
127126
return obj(*args, **kwargs)
128127

129128
wrapper.__dict__ = obj.__dict__
130129
return list(collector._genfunctions(name, wrapper))
131130

132131

133132
def pytest_generate_tests(metafunc):
134-
if 'wish' not in metafunc.fixturenames:
133+
if 'candidate' not in metafunc.fixturenames:
135134
return
136135

137-
ids, params = make_wish_index(metafunc.config)
138-
metafunc.parametrize('wish', params, ids=ids, scope='module')
136+
ids, params = make_candidate_index(metafunc.config)
137+
metafunc.parametrize('candidate', params, ids=ids, scope='module')
139138

140-
if not metafunc.config.getoption('wish_fail'):
139+
if not metafunc.config.getoption('candidates_fail'):
141140
metafunc.function = pytest.mark.xfail(metafunc.function)
142141

143142

144143
def pytest_terminal_summary(terminalreporter):
145-
if not hasattr(terminalreporter.config, '_wish_index_items'):
144+
if not hasattr(terminalreporter.config, '_candicate_index'):
146145
return
147146

148-
hit_state = 'passed' if terminalreporter.config.getoption('wish_fail') else 'xpassed'
147+
hit_state = 'passed' if terminalreporter.config.getoption('candidates_fail') else 'xpassed'
149148
hits = terminalreporter.getreports(hit_state)
150149
terminalreporter.write_sep('=', '%d hit' % len(hits), bold=True)
151150
terminalreporter.write_line('')

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
universal=1
33

44
[pytest]
5-
pep8maxlinelength = 99
5+
pep8maxlinelength = 104
66
norecursedirs =
77
build
88
docs

0 commit comments

Comments
 (0)