Skip to content

Commit

Permalink
Merge pull request #1 from paylogic/initial
Browse files Browse the repository at this point in the history
Initial
  • Loading branch information
bubenkoff committed Jan 3, 2014
2 parents 57007a2 + b3ff6b4 commit 329f4e8
Show file tree
Hide file tree
Showing 14 changed files with 403 additions and 3 deletions.
50 changes: 50 additions & 0 deletions .gitignore
@@ -0,0 +1,50 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
include/
*.egg-info/
.installed.cfg
*.egg
.Python

# 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/
15 changes: 15 additions & 0 deletions .travis.yml
@@ -0,0 +1,15 @@
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
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
8 changes: 8 additions & 0 deletions CHANGES.rst
@@ -0,0 +1,8 @@
Changelog
=========


0.1
---

* Initial public release
20 changes: 20 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,20 @@
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
"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.
5 changes: 5 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,5 @@
include CHANGES.rst
include README.rst
include requirements-testing.txt
include setup.py
include LICENSE
65 changes: 62 additions & 3 deletions README.rst
@@ -1,4 +1,63 @@
pytest-fixture-tools
=====================
.. 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 plugin
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 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.
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 <http://github.com/paylogic/pytest-fixture-tools>`_.

License
-------

This software is licensed under the `MIT license <http://en.wikipedia.org/wiki/MIT_License>`_

See `<LICENSE.txt>`_

© 2013 Paylogic International.
Empty file.
95 changes: 95 additions & 0 deletions pytest_fixture_tools/plugin.py
@@ -0,0 +1,95 @@
"""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):
"""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,
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):
"""Check show_fixture_duplicates option to show fixture duplicates."""
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):
"""Preparing fixture duplicates for output."""
session.perform_collect()
curdir = py.path.local()

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 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[2] not in [f[2] for f in available[argname]]:
available[argname].append(fixture)

if 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, previous_argname)
previous_argname = argname
3 changes: 3 additions & 0 deletions requirements-testing.txt
@@ -0,0 +1,3 @@
pytest-pep8
pytest-cov
pytest-cache
65 changes: 65 additions & 0 deletions 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'],
)
Empty file added tests/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions tests/conftest.py
@@ -0,0 +1,3 @@
"""Configuration for pytest runner."""

pytest_plugins = 'pytester'

0 comments on commit 329f4e8

Please sign in to comment.