From 08b400c79d56cc1ab212131f2e19736ba623856c Mon Sep 17 00:00:00 2001 From: santosh Date: Fri, 19 Aug 2016 16:13:43 +0530 Subject: [PATCH] Initial COmmit For Release 1.0.0 --- CHANGES.rst | 7 ++ MANIFEST.in | 3 + README.rst | 34 ++++++++ conftest.py | 1 + pytest_progress.py | 168 ++++++++++++++++++++++++++++++++++++++++ setup.cfg | 2 + setup.py | 48 ++++++++++++ test_progress_report.py | 30 +++++++ tox.ini | 24 ++++++ version.txt | 1 + 10 files changed, 318 insertions(+) create mode 100644 CHANGES.rst create mode 100644 MANIFEST.in create mode 100644 README.rst create mode 100644 conftest.py create mode 100644 pytest_progress.py create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 test_progress_report.py create mode 100644 tox.ini create mode 100644 version.txt diff --git a/CHANGES.rst b/CHANGES.rst new file mode 100644 index 0000000..1c10574 --- /dev/null +++ b/CHANGES.rst @@ -0,0 +1,7 @@ +Release Notes +------------- + +**1.0.0 (2016-08-18)** + +* Intitial Plugin Release + diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..ee30410 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include README.rst +include tox.ini +include test_progress_report.py \ No newline at end of file diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..6dcde7a --- /dev/null +++ b/README.rst @@ -0,0 +1,34 @@ +pytest-excel +================ + + +pytest-progress is a plugin for `py.test `_ that allows to +print the test progress like number of tests Passed , Failed, Skipped and also +instant test failure messages. + + +Requirements +------------ + +You will need the following prerequisites in order to use pytest-progress: + +- Python 2.7, 3.4 or 3.5 +- pytest 2.9.0 or newer + + + +Installation +------------ + +To install pytest-progress:: + + $ pip install pytest-progress + +Then run your tests with:: + + $ py.test --show-progress + +If you would like more detailed output (one test per line), then you may use the verbose option:: + + $ py.test --verbose + diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..54403b9 --- /dev/null +++ b/conftest.py @@ -0,0 +1 @@ +collect_ignore = ['setup.py', 'test_progress_report.py'] diff --git a/pytest_progress.py b/pytest_progress.py new file mode 100644 index 0000000..ae289ab --- /dev/null +++ b/pytest_progress.py @@ -0,0 +1,168 @@ + +import pytest +from _pytest.terminal import TerminalReporter + + +def pytest_collection_modifyitems(session, config, items): + terminal_reporter = config.pluginmanager.getplugin('terminalreporter') + if terminal_reporter: + terminal_reporter.tests_count = len(items) + + +try: + import xdist +except ImportError: + pass +else: + from distutils.version import LooseVersion + xdist_version = LooseVersion(xdist.__version__) + if xdist_version >= LooseVersion("1.14"): + def pytest_xdist_node_collection_finished(node, ids): + terminal_reporter = node.config.pluginmanager.getplugin('terminalreporter') + if terminal_reporter: + terminal_reporter.tests_count = len(ids) + + + +def pytest_addoption(parser): + group = parser.getgroup("terminal reporting") + group.addoption('--showprogress', '--show-progress', + action="count", + default=0, + dest="progress", + help="Prints test progress on the terminal.") + + + +@pytest.mark.trylast +def pytest_configure(config): + progress = config.option.progress + + if progress and not getattr(config, 'slaveinput', None): + standard_reporter = config.pluginmanager.getplugin('terminalreporter') + instaprogress_reporter = ProgressTerminalReporter(standard_reporter) + + config.pluginmanager.unregister(standard_reporter) + config.pluginmanager.register(instaprogress_reporter, 'terminalreporter') + + +class ProgressTerminalReporter(TerminalReporter): + + + def __init__(self, reporter): + TerminalReporter.__init__(self, reporter.config) + self._tw = reporter._tw + self.tests_count = 0 + self.tests_taken = 0 + self.pass_count = 0 + self.fail_count = 0 + self.skip_count = 0 + self.xpass_count = 0 + self.xfail_count = 0 + self.error_count = 0 + + + def append_pass(self): + self.pass_count = self.pass_count + 1 + self.tests_taken = self.tests_taken + 1 + + + def append_failure(self, report): + + if hasattr(report, "wasxfail"): + self.xpass_count = self.xpass_count + 1 + self.tests_taken = self.tests_taken + 1 + + else: + self.fail_count = self.fail_count + 1 + self.tests_taken = self.tests_taken + 1 + + + def append_error(self): + + self.error_count = self.error_count + 1 + self.tests_taken = self.tests_taken + 1 + + + def append_skipped(self, report): + + if hasattr(report, "wasxfail"): + self.xfail_count = self.xfail_count + 1 + self.tests_taken = self.tests_taken + 1 + + else: + self.skip_count = self.skip_count + 1 + self.tests_taken = self.tests_taken + 1 + + + def pytest_report_teststatus(self, report): + """ Called after every test for test case status""" + + if report.passed: + if report.when == "call": # ignore setup/teardown + self.append_pass() + + elif report.failed: + if report.when == "call": + self.append_failure(report) + + else: + self.append_error() + + elif report.skipped: + self.append_skipped(report) + + if report.when in ("teardown"): + status = (self.tests_taken, self.tests_count, self.pass_count, self.fail_count, + self.skip_count, self.xpass_count, self.xfail_count, self.error_count) + + msg = "%d of %d completed, %d Pass, %d Fail, %d Skip, %d XPass, %d XFail, %d Error" % (status) + self.write_sep("_", msg) + + + def pytest_collectreport(self, report): + # Show errors occurred during the collection instantly. + TerminalReporter.pytest_collectreport(self, report) + if report.failed: + self.rewrite("") # erase the "collecting" message + self.print_failure(report) + + + def pytest_runtest_logreport(self, report): + # Show failures and errors occuring during running a test + # instantly. + TerminalReporter.pytest_runtest_logreport(self, report) + if report.failed and not hasattr(report, 'wasxfail'): + if self.verbosity <= 0: + self._tw.line() + self.print_failure(report) + + + def summary_failures(self): + # Prevent failure summary from being shown since we already + # show the failure instantly after failure has occured. + pass + + + def summary_errors(self): + # Prevent error summary from being shown since we already + # show the error instantly after error has occured. + pass + + + def print_failure(self, report): + if self.config.option.tbstyle != "no": + if self.config.option.tbstyle == "line": + line = self._getcrashline(report) + self.write_line(line) + else: + msg = self._getfailureheadline(report) + if not hasattr(report, 'when'): + msg = "ERROR collecting " + msg + elif report.when == "setup": + msg = "ERROR at setup of " + msg + elif report.when == "teardown": + msg = "ERROR at teardown of " + msg + self.write_sep("_", msg) + if not self.config.getvalue("usepdb"): + self._outrep_summary(report) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..2a9acf1 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +universal = 1 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..84f57b3 --- /dev/null +++ b/setup.py @@ -0,0 +1,48 @@ +import os + +from setuptools import setup + + +def get_version(filename): + + here = os.path.dirname(os.path.abspath(__file__)) + f = open(os.path.join(here, filename)) + version_match = f.read() + f.close() + + if version_match: + return version_match + raise RuntimeError("Unable to find version string.") + + + +setup(name='pytest-progress', + version=get_version('version.txt'), + description='pytest plugin for instant test progress status', + long_description=unicode(open('README.rst').read(), errors='ignore'), + author='santosh', + author_email=u'santosh.srikanta@gmail.com', + url=u'https://github.com/ssrikanta/pytest-progress', + py_modules=['pytest_progress'], + entry_points={'pytest11': ['progress = pytest_progress']}, + install_requires=['pytest>=2.7'], + keywords='py.test pytest report', + classifiers=[ + 'Development Status :: 4 - Beta', + 'Framework :: Pytest', + 'Intended Audience :: Developers', + 'Operating System :: POSIX', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: MacOS :: MacOS X', + 'Topic :: Software Development :: Testing', + 'Topic :: Software Development :: Quality Assurance', + 'Topic :: Software Development :: Libraries', + 'Topic :: Utilities', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.2', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + ] + ) + diff --git a/test_progress_report.py b/test_progress_report.py new file mode 100644 index 0000000..d90c169 --- /dev/null +++ b/test_progress_report.py @@ -0,0 +1,30 @@ + +import pytest + + +class Test_Progress_Report(object): + + + def test_progress_report_01(self): + assert True + + + @pytest.mark.xfail(reason="passed Simply") + def test_progress_report_02(self): + assert True + + + @pytest.mark.skip(reason="Skip for No Reason") + def test_progress_report_03(self): + assert True + + + @pytest.mark.xfail(reason="Failed Simply") + def test_progress_report_04(self): + assert False + + + def test_progress_report_05(self): + assert True is False + + diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..5794ab4 --- /dev/null +++ b/tox.ini @@ -0,0 +1,24 @@ +# Tox (http://tox.testrun.org/) is a tool for running tests +# in multiple virtualenvs. This configuration file will run the +# test suite on all supported python versions. To use it, "pip install tox" +# and then run "tox" from this directory. + +[tox] +envlist = py27-pytest29-supported-xdist, + py27-pytest29-unsupported-xdist, + py34-pytest29-supported-xdist, + py35-pytest29-supported-xdist, + py35-pytest29-unsupported-xdist, + pypy-pytest29-supported-xdist + +[testenv] +passenv = CI TRAVIS_BUILD_ID TRAVIS TRAVIS_BRANCH TRAVIS_JOB_NUMBER TRAVIS_PULL_REQUEST TRAVIS_JOB_ID TRAVIS_REPO_SLUG TRAVIS_COMMIT +deps = + pytest29: pytest>=2.9,<2.10 + openpyxl + supported-xdist: pytest-xdist>=1.14 + unsupported-xdist: pytest-xdist<1.14 + pytest-rerunfailures +commands = + py.test --cov=./ {posargs:test_excel_report.py} + codecov -e TOXENV diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..afaf360 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +1.0.0 \ No newline at end of file