From 2079d30848e31cbb5ecc952b658e901bc593ca8e Mon Sep 17 00:00:00 2001 From: Andrey Makhnach Date: Thu, 2 Jan 2014 12:15:00 +0100 Subject: [PATCH 01/14] initial --- .gitignore | 48 +++++++++++++++++++ .travis.yml | 14 ++++++ CHANGES.rst | 8 ++++ LICENSE | 20 ++++++++ MANIFEST.in | 5 ++ README.rst | 4 -- pytest_fixture_tools/__init__.py | 0 pytest_fixture_tools/plugin.py | 81 ++++++++++++++++++++++++++++++++ requirements-testing.txt | 5 ++ setup.py | 65 +++++++++++++++++++++++++ tests/__init__.py | 0 tests/conftest.py | 3 ++ tests/test_fixture_duplicates.py | 45 ++++++++++++++++++ tox.ini | 27 +++++++++++ 14 files changed, 321 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 CHANGES.rst create mode 100644 LICENSE create mode 100644 MANIFEST.in create mode 100644 pytest_fixture_tools/__init__.py create mode 100644 pytest_fixture_tools/plugin.py create mode 100644 requirements-testing.txt create mode 100644 setup.py create mode 100644 tests/__init__.py create mode 100644 tests/conftest.py create mode 100644 tests/test_fixture_duplicates.py create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cbd3e68 --- /dev/null +++ b/.gitignore @@ -0,0 +1,48 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# Distribution / packaging +bin/ +build/ +develop-eggs/ +dist/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject +.idea/ + +# Rope +.ropeproject + +# Django stuff: +*.log +*.pot + +# Sphinx documentation +docs/_build/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..65c9e02 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: python +# command to install dependencies +install: + - pip install python-coveralls +# # command to run tests +script: python setup.py test +after_success: + - pip install -r requirements-testing.txt -e . + - py.test --cov=pytest_fixture_tools --cov-report=term-missing tests + - coveralls +notifications: + email: + - anatoly.bubenkov@paylogic.com + - andrey.makhnach@paylogic.com \ No newline at end of file diff --git a/CHANGES.rst b/CHANGES.rst new file mode 100644 index 0000000..7f0da74 --- /dev/null +++ b/CHANGES.rst @@ -0,0 +1,8 @@ +Changelog +========= + + +0.1 +--- + +* Initial public release \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..69e15f6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) Andrey Makhnach + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..ca3943d --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +include CHANGES.rst +include README.rst +include requirements-testing.txt +include setup.py +include LICENSE \ No newline at end of file diff --git a/README.rst b/README.rst index 78f6a2f..e69de29 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +0,0 @@ -pytest-fixture-tools -===================== - -Pytest fixture tools plugin diff --git a/pytest_fixture_tools/__init__.py b/pytest_fixture_tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pytest_fixture_tools/plugin.py b/pytest_fixture_tools/plugin.py new file mode 100644 index 0000000..4ff63a0 --- /dev/null +++ b/pytest_fixture_tools/plugin.py @@ -0,0 +1,81 @@ +import py + +from _pytest.python import getlocation +from collections import defaultdict + + +def pytest_addoption(parser): + group = parser.getgroup("general") + group.addoption('--show-fixture-duplicates', + action="store_true", dest="show_fixture_duplicates", default=False, + help="show list of duplicates from available fixtures") + group.addoption('--fixture', + action="store", type=str, dest="fixture_name", default='', + help="Name of specific fixture for which you want to get duplicates") + + +def pytest_cmdline_main(config): + if config.option.show_fixture_duplicates: + show_fixture_duplicates(config) + return 0 + + +def show_fixture_duplicates(config): + from _pytest.main import wrap_session + return wrap_session(config, _show_fixture_duplicates_main) + + +def _show_fixture_duplicates_main(config, session): + session.perform_collect() + curdir = py.path.local() + + tw = py.io.TerminalWriter() + verbose = config.getvalue("verbose") + + fm = session._fixturemanager + + available = defaultdict(list) + for item in session.items: + for argname in fm._arg2fixturedefs: + fixturedefs = fm.getfixturedefs(argname, item.nodeid) + assert fixturedefs is not None + if not fixturedefs: + continue + + for fixturedef in fixturedefs: + loc = getlocation(fixturedef.func, curdir) + + fixture = ( + len(fixturedef.baseid), + fixturedef.func.__module__, + curdir.bestrelpath(loc), + fixturedef + ) + if fixture not in available[argname]: + available[argname].append(fixture) + + def print_duplicates(argname, fixtures, currentargname=None): + if len(fixtures) > 1: + fixtures = sorted(fixtures, cmp=lambda x, y: cmp(x[2], y[2])) + for baseid, module, bestrel, fixturedef in fixtures: + if currentargname != argname: + if not module.startswith("_pytest."): + tw.line() + tw.sep("-", "%s" %(argname,)) + currentargname = argname + if verbose <= 0 and argname[0] == "_": + continue + if verbose > 0: + funcargspec = "{bestrel}".format(bestrel=bestrel) + else: + funcargspec = argname + tw.line(funcargspec, green=True) + + fixture_name = config.option.fixture_name + if fixture_name: + print_duplicates(fixture_name, available[fixture_name]) + else: + available = sorted([(key, items) for key, items in available.items()], cmp=lambda x, y: cmp(x[0], y[0])) + + for argname, fixtures in available: + print_duplicates(argname, fixtures) \ No newline at end of file diff --git a/requirements-testing.txt b/requirements-testing.txt new file mode 100644 index 0000000..7425605 --- /dev/null +++ b/requirements-testing.txt @@ -0,0 +1,5 @@ +mock +pytest-pep8 +pytest-cov +pytest-cache +pytest-xdist \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..ffaeb56 --- /dev/null +++ b/setup.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +import os +import sys + +from setuptools import setup +from setuptools.command.test import test as TestCommand + + +version = '0.1' + + +class ToxTestCommand(TestCommand): + def finalize_options(self): + TestCommand.finalize_options(self) + self.test_args = ['--recreate'] + self.test_suite = True + + def run_tests(self): + #import here, cause outside the eggs aren't loaded + import detox.main + errno = detox.main.main(self.test_args) + sys.exit(errno) + + +dirname = os.path.dirname(__file__) + +long_description = ( + open(os.path.join(dirname, 'README.rst')).read() + '\n' + + open(os.path.join(dirname, 'CHANGES.rst')).read() +) + +setup( + name='pytest-fixture-tools', + description='Plugin for pytest which provides tools for fixtures', + long_description=long_description, + author='Paylogic International', + license='MIT license', + author_email='developers@paylogic.com', + version=version, + classifiers=[ + 'Development Status :: 6 - Mature', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Operating System :: POSIX', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: MacOS :: MacOS X', + 'Topic :: Software Development :: Testing', + 'Topic :: Software Development :: Libraries', + 'Topic :: Utilities', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 3' + ] + [('Programming Language :: Python :: %s' % x) for x in '2.6 2.7 3.0 3.1 3.2 3.3'.split()], + cmdclass={'test': ToxTestCommand}, + install_requires=[ + 'pytest', + ], + # the following makes a plugin available to py.test + entry_points={ + 'pytest11': [ + 'pytest-fixture-tools = pytest_fixture_tools.plugin', + ] + }, + tests_require=['detox'], + packages=['pytest_fixture_tools'], +) \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..5a15122 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,3 @@ +"""Configuration for pytest runner.""" + +pytest_plugins = 'pytester', 'pytest_fixture_tools' \ No newline at end of file diff --git a/tests/test_fixture_duplicates.py b/tests/test_fixture_duplicates.py new file mode 100644 index 0000000..aa552f6 --- /dev/null +++ b/tests/test_fixture_duplicates.py @@ -0,0 +1,45 @@ +import py + + +def test_there_are_not_fixture_duplicates(testdir): + sub1 = testdir.mkpydir("sub1") + sub2 = testdir.mkpydir("sub2") + sub1.join("conftest.py").write(py.code.Source(""" + def pytest_funcarg__arg1(request): + pass + """)) + sub2.join("conftest.py").write(py.code.Source(""" + def pytest_funcarg__arg2(request): + pass + """)) + sub1.join("test_in_sub1.py").write("def test_1(arg1): pass") + sub2.join("test_in_sub2.py").write("def test_2(arg2): pass") + + result = testdir.runpytest("--show-fixture-duplicates") + + assert result.stdout.lines.count('arg1') == 0 + + +def test_there_are_fixture_duplicates(testdir): + + sub1 = testdir.mkpydir("sub1") + sub2 = testdir.mkpydir("sub1/sub2") + sub1.join("conftest.py").write(py.code.Source(""" + import pytest + + @pytest.fixture + def pytest_funcarg__arg1(request): + pass + """)) + sub2.join("conftest.py").write(py.code.Source(""" + import pytest + + @pytest.fixture + def arg1(request): + pass + """)) + sub1.join("test_in_sub1.py").write("def test_1(arg1): pass") + sub2.join("test_in_sub2.py").write("def test_2(arg1): pass") + + result = testdir.runpytest('--show-fixture-duplicates') + assert result.stdout.lines.count('arg1') == 2 \ No newline at end of file diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..e6d596b --- /dev/null +++ b/tox.ini @@ -0,0 +1,27 @@ +[tox] +distshare={homedir}/.tox/distshare +envlist=py26,py27,py27-xdist,py27-pytest-latest,py33 +indexserver= + pypi = https://pypi.python.org/simple + +[testenv] +commands= py.test pytest_fixture_tools tests --pep8 --junitxml={envlogdir}/junit-{envname}.xml +deps = -r{toxinidir}/requirements-testing.txt + +[testenv:py27-coverage] +commands= py.test pytest_fixture_tools tests --cov=pytest_fixture_tools --pep8 --junitxml={envlogdir}/junit-{envname}.xml + +[testenv:py27-xdist] +basepython=python2.7 +commands= + py.test pytest_fixture_tools tests -n3 --pep8 -rfsxX \ + --junitxml={envlogdir}/junit-{envname}.xml + +[testenv:py27-pytest-latest] +basepython=python2.7 +deps = + {[testenv]deps} + hg+ssh://hg@bitbucket.org/hpk42/pytest#egg=pytest + +[pytest] +pep8maxlinelength=120 \ No newline at end of file From e42d9e6786461f1d755136033a7e079ae784388f Mon Sep 17 00:00:00 2001 From: Andrey Makhnach Date: Thu, 2 Jan 2014 13:27:36 +0100 Subject: [PATCH 02/14] Added readme. Fixed pep8. Make tests passed. --- LICENSE | 2 +- README.rst | 60 ++++++++++++++++++++++++++++++++ pytest_fixture_tools/plugin.py | 18 +++++----- tests/conftest.py | 2 +- tests/test_fixture_duplicates.py | 14 +++++--- tox.ini | 17 ++++----- 6 files changed, 87 insertions(+), 26 deletions(-) diff --git a/LICENSE b/LICENSE index 69e15f6..34d12fa 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) Andrey Makhnach +Copyright (c) Paylogic International Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.rst b/README.rst index e69de29..25bc1dc 100644 --- a/README.rst +++ b/README.rst @@ -0,0 +1,60 @@ +.. image:: https://api.travis-ci.org/paylogic/pytest-fixture-tools.png + :target: https://travis-ci.org/paylogic/pytest-fixture-tools +.. image:: https://pypip.in/v/pytest-fixture-tools/badge.png + :target: https://crate.io/packages/pytest-fixture-tools/ +.. image:: https://coveralls.io/repos/paylogic/pytest-fixture-tools/badge.png?branch=master + :target: https://coveralls.io/r/paylogic/pytest-fixture-tools + +pytest-fixture-tools: Pytest fixture tools plugin +=============================================================== + +The ``pytest-fixture-tools`` package is a pytest plugin which provides various tools for fixture. + + +Installation +------------ + +.. sourcecode:: + + pip install pytest-fixture-tools + + +Usage +----- + +If you have already installed ``pytest-fixture-tools`` plugin then you can use one of its commands. + +``--show-fixture-duplicates`` - will collect all fixtures and print you a list of duplicates for each fixture. +With ``--show-fixture-duplicates`` you can use ``--fixture name_of_fixture`` option to get list of duplicates only for specific fixture + +.. sourcecode:: + + py.test tests/ --show-fixture-duplicates --fixture order + + # output + ============================================================================================ test session starts ============================================================================================ + platform linux2 -- Python 2.7.3 -- pytest-2.5.1 -- /home/batman/.virtualenvs/arkham-city/bin/python + Tests are shuffled using seed number 355495648184. + cachedir: /home/batman/.virtualenvs/arkham-city/.cache + plugins: fixture-tools, random, bdd-splinter, pep8, cov, contextfixture, bdd, xdist, instafail, cache + collected 2347 items / 1 skipped + + --------------------------------------------------------------------------------------------------- order --------------------------------------------------------------------------------------------------- + tests/fixtures/order.py:30 + tests/unit/api/conftest.py:261 + + +Contact +------- + +If you have questions, bug reports, suggestions, etc. please create an issue on +the `GitHub project page `_. + +License +------- + +This software is licensed under the `MIT license `_ + +See ``_ + +© 2013 Paylogic International. \ No newline at end of file diff --git a/pytest_fixture_tools/plugin.py b/pytest_fixture_tools/plugin.py index 4ff63a0..7798f3f 100644 --- a/pytest_fixture_tools/plugin.py +++ b/pytest_fixture_tools/plugin.py @@ -7,11 +7,11 @@ def pytest_addoption(parser): group = parser.getgroup("general") group.addoption('--show-fixture-duplicates', - action="store_true", dest="show_fixture_duplicates", default=False, - help="show list of duplicates from available fixtures") + action="store_true", dest="show_fixture_duplicates", default=False, + help="show list of duplicates from available fixtures") group.addoption('--fixture', - action="store", type=str, dest="fixture_name", default='', - help="Name of specific fixture for which you want to get duplicates") + action="store", type=str, dest="fixture_name", default='', + help="Name of specific fixture for which you want to get duplicates") def pytest_cmdline_main(config): @@ -56,17 +56,17 @@ def _show_fixture_duplicates_main(config, session): def print_duplicates(argname, fixtures, currentargname=None): if len(fixtures) > 1: - fixtures = sorted(fixtures, cmp=lambda x, y: cmp(x[2], y[2])) + fixtures = sorted(fixtures, key=lambda key: key[2]) for baseid, module, bestrel, fixturedef in fixtures: if currentargname != argname: if not module.startswith("_pytest."): tw.line() - tw.sep("-", "%s" %(argname,)) + tw.sep("-", argname) currentargname = argname if verbose <= 0 and argname[0] == "_": continue if verbose > 0: - funcargspec = "{bestrel}".format(bestrel=bestrel) + funcargspec = bestrel else: funcargspec = argname tw.line(funcargspec, green=True) @@ -75,7 +75,7 @@ def print_duplicates(argname, fixtures, currentargname=None): if fixture_name: print_duplicates(fixture_name, available[fixture_name]) else: - available = sorted([(key, items) for key, items in available.items()], cmp=lambda x, y: cmp(x[0], y[0])) + available = sorted([(key, items) for key, items in available.items()], key=lambda key: key[0]) for argname, fixtures in available: - print_duplicates(argname, fixtures) \ No newline at end of file + print_duplicates(argname, fixtures) diff --git a/tests/conftest.py b/tests/conftest.py index 5a15122..2f0977f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,3 @@ """Configuration for pytest runner.""" -pytest_plugins = 'pytester', 'pytest_fixture_tools' \ No newline at end of file +pytest_plugins = 'pytester', 'pytest_fixture_tools' diff --git a/tests/test_fixture_duplicates.py b/tests/test_fixture_duplicates.py index aa552f6..6e33964 100644 --- a/tests/test_fixture_duplicates.py +++ b/tests/test_fixture_duplicates.py @@ -5,11 +5,17 @@ def test_there_are_not_fixture_duplicates(testdir): sub1 = testdir.mkpydir("sub1") sub2 = testdir.mkpydir("sub2") sub1.join("conftest.py").write(py.code.Source(""" - def pytest_funcarg__arg1(request): + import pytest + + @pytest.fixture + def arg1(request): pass """)) sub2.join("conftest.py").write(py.code.Source(""" - def pytest_funcarg__arg2(request): + import pytest + + @pytest.fixture + def arg2(request): pass """)) sub1.join("test_in_sub1.py").write("def test_1(arg1): pass") @@ -28,7 +34,7 @@ def test_there_are_fixture_duplicates(testdir): import pytest @pytest.fixture - def pytest_funcarg__arg1(request): + def arg1(request): pass """)) sub2.join("conftest.py").write(py.code.Source(""" @@ -42,4 +48,4 @@ def arg1(request): sub2.join("test_in_sub2.py").write("def test_2(arg1): pass") result = testdir.runpytest('--show-fixture-duplicates') - assert result.stdout.lines.count('arg1') == 2 \ No newline at end of file + assert result.stdout.lines.count('arg1') == 2 diff --git a/tox.ini b/tox.ini index e6d596b..80b9b29 100644 --- a/tox.ini +++ b/tox.ini @@ -1,27 +1,22 @@ [tox] distshare={homedir}/.tox/distshare -envlist=py26,py27,py27-xdist,py27-pytest-latest,py33 +envlist=py26,py27,py27-pytest-latest,py33 indexserver= pypi = https://pypi.python.org/simple [testenv] -commands= py.test pytest_fixture_tools tests --pep8 --junitxml={envlogdir}/junit-{envname}.xml +commands= py.test --junitxml={envlogdir}/junit-{envname}.xml deps = -r{toxinidir}/requirements-testing.txt [testenv:py27-coverage] -commands= py.test pytest_fixture_tools tests --cov=pytest_fixture_tools --pep8 --junitxml={envlogdir}/junit-{envname}.xml - -[testenv:py27-xdist] -basepython=python2.7 -commands= - py.test pytest_fixture_tools tests -n3 --pep8 -rfsxX \ - --junitxml={envlogdir}/junit-{envname}.xml +commands= py.test --cov=pytest_fixture_tools --junitxml={envlogdir}/junit-{envname}.xml [testenv:py27-pytest-latest] basepython=python2.7 deps = {[testenv]deps} - hg+ssh://hg@bitbucket.org/hpk42/pytest#egg=pytest + hg+https://bitbucket.org/hpk42/pytest [pytest] -pep8maxlinelength=120 \ No newline at end of file +pep8maxlinelength=120 +addopts = pytest_fixture_tools tests --pep8 \ No newline at end of file From d825b7b863afb1fb6959303834955507462da829 Mon Sep 17 00:00:00 2001 From: Andrey Makhnach Date: Thu, 2 Jan 2014 13:29:29 +0100 Subject: [PATCH 03/14] Changed readme a little bit. --- README.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 25bc1dc..68ac031 100644 --- a/README.rst +++ b/README.rst @@ -31,7 +31,9 @@ With ``--show-fixture-duplicates`` you can use ``--fixture name_of_fixture`` opt py.test tests/ --show-fixture-duplicates --fixture order - # output +Output can look like this: + +.. sourcecode:: ============================================================================================ test session starts ============================================================================================ platform linux2 -- Python 2.7.3 -- pytest-2.5.1 -- /home/batman/.virtualenvs/arkham-city/bin/python Tests are shuffled using seed number 355495648184. From 0ea94742b06e7f24725cf284755df417c3a23558 Mon Sep 17 00:00:00 2001 From: Andrey Makhnach Date: Thu, 2 Jan 2014 13:36:58 +0100 Subject: [PATCH 04/14] Changed readme a little bit. --- README.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 68ac031..0a9c510 100644 --- a/README.rst +++ b/README.rst @@ -34,14 +34,15 @@ With ``--show-fixture-duplicates`` you can use ``--fixture name_of_fixture`` opt Output can look like this: .. sourcecode:: - ============================================================================================ test session starts ============================================================================================ + + ========================================== test session starts ========================================== platform linux2 -- Python 2.7.3 -- pytest-2.5.1 -- /home/batman/.virtualenvs/arkham-city/bin/python Tests are shuffled using seed number 355495648184. cachedir: /home/batman/.virtualenvs/arkham-city/.cache plugins: fixture-tools, random, bdd-splinter, pep8, cov, contextfixture, bdd, xdist, instafail, cache collected 2347 items / 1 skipped - --------------------------------------------------------------------------------------------------- order --------------------------------------------------------------------------------------------------- + ------------------------------------------------- order ------------------------------------------------- tests/fixtures/order.py:30 tests/unit/api/conftest.py:261 From 22f647db21411fe731fcf0f6e9c2f877a7fbf573 Mon Sep 17 00:00:00 2001 From: Andrey Makhnach Date: Thu, 2 Jan 2014 15:19:33 +0100 Subject: [PATCH 05/14] Added docstings. Made refactoring. --- LICENSE => LICENSE.txt | 0 pytest_fixture_tools/plugin.py | 65 ++++++++++++++++++++------------ tests/test_fixture_duplicates.py | 7 +++- 3 files changed, 45 insertions(+), 27 deletions(-) rename LICENSE => LICENSE.txt (100%) diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/pytest_fixture_tools/plugin.py b/pytest_fixture_tools/plugin.py index 7798f3f..48c7e66 100644 --- a/pytest_fixture_tools/plugin.py +++ b/pytest_fixture_tools/plugin.py @@ -1,10 +1,16 @@ +"""Pytest fixture tools plugin.""" + import py from _pytest.python import getlocation from collections import defaultdict +tw = py.io.TerminalWriter() +verbose = 1 + def pytest_addoption(parser): + """Pytest commandline hook which register argparse-style options and ini-style config values.""" group = parser.getgroup("general") group.addoption('--show-fixture-duplicates', action="store_true", dest="show_fixture_duplicates", default=False, @@ -15,28 +21,53 @@ def pytest_addoption(parser): def pytest_cmdline_main(config): + """Pytest commandline hook which called for performing the main command line action. The default + implementation will invoke the configure hooks and runtest_mainloop.""" if config.option.show_fixture_duplicates: show_fixture_duplicates(config) return 0 def show_fixture_duplicates(config): + """Wrap pytest session to show duplicates.""" from _pytest.main import wrap_session return wrap_session(config, _show_fixture_duplicates_main) +def print_duplicates(argname, fixtures, previous_argname): + """Print duplicates with TerminalWriter.""" + if len(fixtures) > 1: + fixtures = sorted(fixtures, key=lambda key: key[2]) + + for baseid, module, bestrel, fixturedef in fixtures: + + if previous_argname != argname: + tw.line() + tw.sep("-", argname) + previous_argname = argname + + if verbose <= 0 and argname[0] == "_": + continue + + funcargspec = bestrel + + tw.line(funcargspec) + + def _show_fixture_duplicates_main(config, session): + """Prepearint fixture duplicates for output.""" session.perform_collect() curdir = py.path.local() - tw = py.io.TerminalWriter() - verbose = config.getvalue("verbose") - fm = session._fixturemanager + fixture_name = config.option.fixture_name available = defaultdict(list) + arg2fixturedefs = ([fixture_name] + if fixture_name and fixture_name in fm._arg2fixturedefs + else fm._arg2fixturedefs) for item in session.items: - for argname in fm._arg2fixturedefs: + for argname in arg2fixturedefs: fixturedefs = fm.getfixturedefs(argname, item.nodeid) assert fixturedefs is not None if not fixturedefs: @@ -51,31 +82,15 @@ def _show_fixture_duplicates_main(config, session): curdir.bestrelpath(loc), fixturedef ) - if fixture not in available[argname]: + if fixture[2] not in [f[2] for f in available[argname]]: available[argname].append(fixture) - def print_duplicates(argname, fixtures, currentargname=None): - if len(fixtures) > 1: - fixtures = sorted(fixtures, key=lambda key: key[2]) - for baseid, module, bestrel, fixturedef in fixtures: - if currentargname != argname: - if not module.startswith("_pytest."): - tw.line() - tw.sep("-", argname) - currentargname = argname - if verbose <= 0 and argname[0] == "_": - continue - if verbose > 0: - funcargspec = bestrel - else: - funcargspec = argname - tw.line(funcargspec, green=True) - - fixture_name = config.option.fixture_name if fixture_name: - print_duplicates(fixture_name, available[fixture_name]) + print_duplicates(fixture_name, available[fixture_name], None) else: available = sorted([(key, items) for key, items in available.items()], key=lambda key: key[0]) + previous_argname = None for argname, fixtures in available: - print_duplicates(argname, fixtures) + print_duplicates(argname, fixtures, previous_argname) + previous_argname = argname diff --git a/tests/test_fixture_duplicates.py b/tests/test_fixture_duplicates.py index 6e33964..951b475 100644 --- a/tests/test_fixture_duplicates.py +++ b/tests/test_fixture_duplicates.py @@ -2,6 +2,7 @@ def test_there_are_not_fixture_duplicates(testdir): + """Check that --show-fixture-duplicates wont give us list of duplicates.""" sub1 = testdir.mkpydir("sub1") sub2 = testdir.mkpydir("sub2") sub1.join("conftest.py").write(py.code.Source(""" @@ -27,7 +28,7 @@ def arg2(request): def test_there_are_fixture_duplicates(testdir): - + """Check that --show-fixture-duplicates will give us list of duplicates.""" sub1 = testdir.mkpydir("sub1") sub2 = testdir.mkpydir("sub1/sub2") sub1.join("conftest.py").write(py.code.Source(""" @@ -48,4 +49,6 @@ def arg1(request): sub2.join("test_in_sub2.py").write("def test_2(arg1): pass") result = testdir.runpytest('--show-fixture-duplicates') - assert result.stdout.lines.count('arg1') == 2 + + assert result.stdout.lines.count('sub1/conftest.py:5') == 1 + assert result.stdout.lines.count('sub1/sub2/conftest.py:5') == 1 From 84f588d85ee29467866dc7dc91debc50fd717788 Mon Sep 17 00:00:00 2001 From: Andrey Makhnach Date: Fri, 3 Jan 2014 00:46:26 +0100 Subject: [PATCH 06/14] Fixed doc strings. --- pytest_fixture_tools/plugin.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pytest_fixture_tools/plugin.py b/pytest_fixture_tools/plugin.py index 48c7e66..664a64b 100644 --- a/pytest_fixture_tools/plugin.py +++ b/pytest_fixture_tools/plugin.py @@ -10,7 +10,7 @@ def pytest_addoption(parser): - """Pytest commandline hook which register argparse-style options and ini-style config values.""" + """Add commandline options show-fixture-duplicates and fixture.""" group = parser.getgroup("general") group.addoption('--show-fixture-duplicates', action="store_true", dest="show_fixture_duplicates", default=False, @@ -21,8 +21,7 @@ def pytest_addoption(parser): def pytest_cmdline_main(config): - """Pytest commandline hook which called for performing the main command line action. The default - implementation will invoke the configure hooks and runtest_mainloop.""" + """Check show_fixture_duplicates option to show fixture duplicates.""" if config.option.show_fixture_duplicates: show_fixture_duplicates(config) return 0 From b8612021090755f1f972856b95969910b1386a90 Mon Sep 17 00:00:00 2001 From: Andrey Makhnach Date: Fri, 3 Jan 2014 09:27:27 +0100 Subject: [PATCH 07/14] Added doc string for test_fixture_duplicate module. --- tests/test_fixture_duplicates.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_fixture_duplicates.py b/tests/test_fixture_duplicates.py index 951b475..27939fd 100644 --- a/tests/test_fixture_duplicates.py +++ b/tests/test_fixture_duplicates.py @@ -1,3 +1,4 @@ +"""Test for checking getting of duplicates.""" import py From 3d41719133c8053edbc2c915b680ce7f5c663a71 Mon Sep 17 00:00:00 2001 From: Anatoly Bubenkov Date: Fri, 3 Jan 2014 09:33:28 +0100 Subject: [PATCH 08/14] Update .travis.yml --- .travis.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 65c9e02..8e6c482 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,15 @@ language: python # command to install dependencies install: - - pip install python-coveralls + - virtualenv . + - bin/pip install python-coveralls # # command to run tests -script: python setup.py test +script: bin/python setup.py test after_success: - - pip install -r requirements-testing.txt -e . - - py.test --cov=pytest_fixture_tools --cov-report=term-missing tests - - coveralls + - bin/pip install -r requirements-testing.txt -e . + - bin/py.test --cov=pytest_fixture_tools --cov-report=term-missing tests + - bin/coveralls notifications: email: - anatoly.bubenkov@paylogic.com - - andrey.makhnach@paylogic.com \ No newline at end of file + - andrey.makhnach@paylogic.com From bed3fa95184d529ab4dc5b747ec79c4fd991081d Mon Sep 17 00:00:00 2001 From: Anatoly Bubenkov Date: Fri, 3 Jan 2014 09:57:54 +0100 Subject: [PATCH 09/14] Update .travis.yml --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8e6c482..f4f4331 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: python # command to install dependencies install: - - virtualenv . - - bin/pip install python-coveralls + - virtualenv . --no-pip + - bin/easy_intall python-coveralls # # command to run tests script: bin/python setup.py test after_success: From 866eee15964a4fbcec826a3c20d2b3184316c30f Mon Sep 17 00:00:00 2001 From: Anatoly Bubenkov Date: Fri, 3 Jan 2014 10:00:01 +0100 Subject: [PATCH 10/14] Update .travis.yml --- .travis.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index f4f4331..ce7dcb8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,13 @@ language: python # command to install dependencies install: - - virtualenv . --no-pip - - bin/easy_intall python-coveralls + - pip install python-coveralls # # command to run tests -script: bin/python setup.py test +script: python setup.py test after_success: - - bin/pip install -r requirements-testing.txt -e . - - bin/py.test --cov=pytest_fixture_tools --cov-report=term-missing tests - - bin/coveralls + - pip install -r requirements-testing.txt -e . + - py.test --cov=pytest_fixture_tools --cov-report=term-missing tests + - coveralls notifications: email: - anatoly.bubenkov@paylogic.com From 608b50bd4d2948b3c842623bc4b94f1876cf6810 Mon Sep 17 00:00:00 2001 From: Anatoly Bubenkov Date: Fri, 3 Jan 2014 10:15:11 +0100 Subject: [PATCH 11/14] python --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index cbd3e68..8ba6e0b 100644 --- a/.gitignore +++ b/.gitignore @@ -13,9 +13,11 @@ lib64/ parts/ sdist/ var/ +include/ *.egg-info/ .installed.cfg *.egg +.Python # Installer logs pip-log.txt From 90bd869fdf41136ed9a5a4289cb5754b32687e16 Mon Sep 17 00:00:00 2001 From: Anatoly Bubenkov Date: Fri, 3 Jan 2014 11:44:33 +0100 Subject: [PATCH 12/14] fix venv version --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ce7dcb8..3ed29fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: python # command to install dependencies install: + - pip install virtualenv==1.10 - pip install python-coveralls # # command to run tests script: python setup.py test From 2efcd8fbf08e8b56b21400068e6886d945a40fb5 Mon Sep 17 00:00:00 2001 From: Andrey Makhnach Date: Fri, 3 Jan 2014 13:05:15 +0100 Subject: [PATCH 13/14] Changed requirements. --- requirements-testing.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/requirements-testing.txt b/requirements-testing.txt index 7425605..3edfbad 100644 --- a/requirements-testing.txt +++ b/requirements-testing.txt @@ -1,5 +1,3 @@ -mock pytest-pep8 pytest-cov pytest-cache -pytest-xdist \ No newline at end of file From b3ff6b43e3bbfa55b0674e9046a696287dad8989 Mon Sep 17 00:00:00 2001 From: Andrey Makhnach Date: Fri, 3 Jan 2014 13:44:44 +0100 Subject: [PATCH 14/14] Fixed comments for pull request. --- pytest_fixture_tools/plugin.py | 2 +- tests/conftest.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytest_fixture_tools/plugin.py b/pytest_fixture_tools/plugin.py index 664a64b..cf31f23 100644 --- a/pytest_fixture_tools/plugin.py +++ b/pytest_fixture_tools/plugin.py @@ -54,7 +54,7 @@ def print_duplicates(argname, fixtures, previous_argname): def _show_fixture_duplicates_main(config, session): - """Prepearint fixture duplicates for output.""" + """Preparing fixture duplicates for output.""" session.perform_collect() curdir = py.path.local() diff --git a/tests/conftest.py b/tests/conftest.py index 2f0977f..d36f0df 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,3 @@ """Configuration for pytest runner.""" -pytest_plugins = 'pytester', 'pytest_fixture_tools' +pytest_plugins = 'pytester'