Skip to content

Commit

Permalink
Merge pull request #2613 from nicoddemus/features
Browse files Browse the repository at this point in the history
Merge master into features
  • Loading branch information
RonnyPfannschmidt committed Jul 27, 2017
2 parents 309152d + 3d89905 commit ddf1751
Show file tree
Hide file tree
Showing 38 changed files with 273 additions and 71 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Michael Birtwell
Michael Droettboom
Michael Seifert
Michal Wajszczuk
Mihai Capotă
Mike Lundy
Nathaniel Waisbrot
Ned Batchelder
Expand Down
73 changes: 51 additions & 22 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ If you are reporting a bug, please include:

* Your operating system name and version.
* Any details about your local setup that might be helpful in troubleshooting,
specifically Python interpreter version,
installed libraries and pytest version.
specifically the Python interpreter version, installed libraries, and pytest
version.
* Detailed steps to reproduce the bug.

If you can write a demonstration test that currently fails but should pass (xfail),
that is a very useful commit to make as well, even if you can't find how
to fix the bug yet.
If you can write a demonstration test that currently fails but should pass
(xfail), that is a very useful commit to make as well, even if you cannot
fix the bug itself.


.. _fixbugs:
Expand Down Expand Up @@ -158,19 +158,40 @@ As stated, the objective is to share maintenance and avoid "plugin-abandon".
.. _`pull requests`:
.. _pull-requests:

Preparing Pull Requests on GitHub
---------------------------------
Preparing Pull Requests
-----------------------

Short version
~~~~~~~~~~~~~

#. Fork the repository;
#. Target ``master`` for bugfixes and doc changes;
#. Target ``features`` for new features or functionality changes.
#. Follow **PEP-8**. There's a ``tox`` command to help fixing it: ``tox -e fix-lint``.
#. Tests are run using ``tox``::

tox -e linting,py27,py36

The test environments above are usually enough to cover most cases locally.

#. Write a ``changelog`` entry: ``changelog/2574.bugfix``, use issue id number
and one of ``bugfix``, ``removal``, ``feature``, ``vendor``, ``doc`` or
``trivial`` for the issue type.
#. Add yourself to ``AUTHORS`` file if not there yet, in alphabetical order.

.. note::
What is a "pull request"? It informs project's core developers about the
changes you want to review and merge. Pull requests are stored on
`GitHub servers <https://github.com/pytest-dev/pytest/pulls>`_.
Once you send a pull request, we can discuss its potential modifications and
even add more commits to it later on.

There's an excellent tutorial on how Pull Requests work in the
`GitHub Help Center <https://help.github.com/articles/using-pull-requests/>`_,
but here is a simple overview:
Long version
~~~~~~~~~~~~

What is a "pull request"? It informs the project's core developers about the
changes you want to review and merge. Pull requests are stored on
`GitHub servers <https://github.com/pytest-dev/pytest/pulls>`_.
Once you send a pull request, we can discuss its potential modifications and
even add more commits to it later on. There's an excellent tutorial on how Pull
Requests work in the
`GitHub Help Center <https://help.github.com/articles/using-pull-requests/>`_.

Here is a simple overview, with pytest-specific bits:

#. Fork the
`pytest GitHub repository <https://github.com/pytest-dev/pytest>`__. It's
Expand Down Expand Up @@ -214,12 +235,18 @@ but here is a simple overview:
This command will run tests via the "tox" tool against Python 2.7 and 3.6
and also perform "lint" coding-style checks.

#. You can now edit your local working copy.
#. You can now edit your local working copy. Please follow PEP-8.

You can now make the changes you want and run the tests again as necessary.

To run tests on Python 2.7 and pass options to pytest (e.g. enter pdb on
failure) to pytest you can do::
If you have too much linting errors, try running::

$ tox -e fix-lint

To fix pep8 related errors.

You can pass different options to ``tox``. For example, to run tests on Python 2.7 and pass options to pytest
(e.g. enter pdb on failure) to pytest you can do::

$ tox -e py27 -- --pdb

Expand All @@ -232,9 +259,11 @@ but here is a simple overview:
$ git commit -a -m "<commit message>"
$ git push -u

Make sure you add a message to ``CHANGELOG.rst`` and add yourself to
``AUTHORS``. If you are unsure about either of these steps, submit your
pull request and we'll help you fix it up.
#. Create a new changelog entry in ``changelog``. The file should be named ``<issueid>.<type>``,
where *issueid* is the number of the issue related to the change and *type* is one of
``bugfix``, ``removal``, ``feature``, ``vendor``, ``doc`` or ``trivial``.

#. Add yourself to ``AUTHORS`` file if not there yet, in alphabetical order.

#. Finally, submit a pull request through the GitHub website using this data::

Expand Down
24 changes: 24 additions & 0 deletions _pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def pytest_load_initial_conftests(early_config, parser, args):
ns = early_config.known_args_namespace
if ns.capture == "fd":
_py36_windowsconsoleio_workaround()
_colorama_workaround()
_readline_workaround()
pluginmanager = early_config.pluginmanager
capman = CaptureManager(ns.capture)
Expand Down Expand Up @@ -253,6 +254,11 @@ def writelines(self, linelist):
data = ''.join(linelist)
self.write(data)

@property
def name(self):
"""Ensure that file.name is a string."""
return repr(self.buffer)

def __getattr__(self, name):
return getattr(object.__getattribute__(self, "buffer"), name)

Expand Down Expand Up @@ -473,6 +479,24 @@ def buffer(self):
raise AttributeError('redirected stdin has no attribute buffer')


def _colorama_workaround():
"""
Ensure colorama is imported so that it attaches to the correct stdio
handles on Windows.
colorama uses the terminal on import time. So if something does the
first import of colorama while I/O capture is active, colorama will
fail in various ways.
"""

if not sys.platform.startswith('win32'):
return
try:
import colorama # noqa
except ImportError:
pass


def _readline_workaround():
"""
Ensure readline is imported so that it attaches to the correct stdio
Expand Down
1 change: 0 additions & 1 deletion _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,6 @@ def _preparse(self, args, addopts=True):
self.pluginmanager.load_setuptools_entrypoints('pytest11')
self.pluginmanager.consider_env()
self.known_args_namespace = ns = self._parser.parse_known_args(args, namespace=self.option.copy())
confcutdir = self.known_args_namespace.confcutdir
if self.known_args_namespace.confcutdir is None and self.inifile:
confcutdir = py.path.local(self.inifile).dirname
self.known_args_namespace.confcutdir = confcutdir
Expand Down
2 changes: 1 addition & 1 deletion _pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def repr_failure(self, excinfo):
return super(DoctestItem, self).repr_failure(excinfo)

def reportinfo(self):
return self.fspath, None, "[doctest] %s" % self.name
return self.fspath, self.dtest.lineno, "[doctest] %s" % self.name


def _get_flag_lookup():
Expand Down
7 changes: 5 additions & 2 deletions _pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,11 @@ def popen(self, cmdargs, stdout, stderr, **kw):
env['PYTHONPATH'] = os.pathsep.join(filter(None, [
str(os.getcwd()), env.get('PYTHONPATH', '')]))
kw['env'] = env
return subprocess.Popen(cmdargs,
stdout=stdout, stderr=stderr, **kw)

popen = subprocess.Popen(cmdargs, stdin=subprocess.PIPE, stdout=stdout, stderr=stderr, **kw)
popen.stdin.close()

return popen

def run(self, *cmdargs):
"""Run a command with arguments.
Expand Down
7 changes: 4 additions & 3 deletions _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,10 @@ def _importtestmodule(self):
if e.allow_module_level:
raise
raise self.CollectError(
"Using pytest.skip outside of a test is not allowed. If you are "
"trying to decorate a test function, use the @pytest.mark.skip "
"or @pytest.mark.skipif decorators instead."
"Using pytest.skip outside of a test is not allowed. "
"To decorate a test function, use the @pytest.mark.skip "
"or @pytest.mark.skipif decorators instead, and to skip a "
"module use `pytestmark = pytest.mark.{skip,skipif}."
)
self.config.pluginmanager.consider_module(mod)
return mod
Expand Down
2 changes: 1 addition & 1 deletion _pytest/skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,4 @@ def show_skipped(terminalreporter, lines):
reason = reason[9:]
lines.append(
"SKIP [%d] %s:%d: %s" %
(num, fspath, lineno, reason))
(num, fspath, lineno + 1, reason))
5 changes: 3 additions & 2 deletions _pytest/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def pytest_addoption(parser):
'-W', '--pythonwarnings', action='append',
help="set which warnings to report, see -W option of python itself.")
parser.addini("filterwarnings", type="linelist",
help="Each line specifies warning filter pattern which would be passed"
"to warnings.filterwarnings. Process after -W and --pythonwarnings.")
help="Each line specifies a pattern for "
"warnings.filterwarnings. "
"Processed after -W and --pythonwarnings.")


@contextmanager
Expand Down
1 change: 1 addition & 0 deletions changelog/2023.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set ``stdin`` to a closed ``PIPE`` in ``pytester.py.Testdir.popen()`` for avoid unwanted interactive ``pdb``
1 change: 1 addition & 0 deletions changelog/2375.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing ``encoding`` attribute to ``sys.std*`` streams when using ``capsys`` capture mode.
1 change: 0 additions & 1 deletion changelog/2375.trivial

This file was deleted.

1 change: 1 addition & 0 deletions changelog/2510.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix terminal color changing to black on Windows if ``colorama`` is imported in a ``conftest.py`` file.
2 changes: 1 addition & 1 deletion changelog/2533.trivial
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Renamed the utility function `_pytest.compat._escape_strings` to `_ascii_escaped` to better communicate the function's purpose.
Renamed the utility function ``_pytest.compat._escape_strings`` to ``_ascii_escaped`` to better communicate the function's purpose.
1 change: 1 addition & 0 deletions changelog/2546.trivial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve error message for CollectError with skip/skipif.
1 change: 1 addition & 0 deletions changelog/2548.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix line number when reporting summary of skipped tests.
1 change: 1 addition & 0 deletions changelog/2555.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
capture: ensure that EncodedFile.name is a string.
2 changes: 1 addition & 1 deletion changelog/2562.trivial
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Emit yield test warning only once per generator
Emit warning about ``yield`` tests being deprecated only once per generator.
2 changes: 1 addition & 1 deletion changelog/2574.bugfix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
The options --fixtures and --fixtures-per-test will now keep indentation within docstrings.
The options ```--fixtures`` and ```--fixtures-per-test`` will now keep indentation within docstrings.
2 changes: 1 addition & 1 deletion changelog/2581.trivial
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fixed all flake8 errors and warnings
Fixed all flake8 errors and warnings.
1 change: 1 addition & 0 deletions changelog/2582.trivial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added ``fix-lint`` tox environment to run automatic pep8 fixes on the code.
1 change: 1 addition & 0 deletions changelog/2610.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doctests line numbers are now reported correctly, fixing `pytest-sugar#122 <https://github.com/Frozenball/pytest-sugar/issues/122>`_.
1 change: 1 addition & 0 deletions changelog/2620.trivial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show multiple issue links in CHANGELOG entries.
3 changes: 2 additions & 1 deletion changelog/_template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

{% if definitions[category]['showcontent'] %}
{% for text, values in sections[section][category]|dictsort(by='value') %}
- {{ text }}{% if category != 'vendor' %} (`{{ values[0] }} <https://github.com/pytest-dev/pytest/issues/{{ values[0][1:] }}>`_){% endif %}
{% set issue_joiner = joiner(', ') %}
- {{ text }}{% if category != 'vendor' %} ({% for value in values|sort %}{{ issue_joiner() }}`{{ value }} <https://github.com/pytest-dev/pytest/issues/{{ value[1:] }}>`_{% endfor %}){% endif %}


{% endfor %}
Expand Down
2 changes: 2 additions & 0 deletions doc/en/cache.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.. _`cache_provider`:
.. _cache:


Cache: working with cross-testrun state
=======================================
Expand Down
3 changes: 2 additions & 1 deletion doc/en/contents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ Full pytest documentation
plugins
writing_plugins

example/index
goodpractices
pythonpath
customize
example/index
bash-completion

backwards-compatibility
Expand Down
30 changes: 22 additions & 8 deletions doc/en/customize.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Basic test configuration
===================================
Configuration
=============

Command line options and configuration file settings
-----------------------------------------------------------------
Expand All @@ -15,17 +15,31 @@ which were registered by installed plugins.
.. _rootdir:
.. _inifiles:

initialization: determining rootdir and inifile
Initialization: determining rootdir and inifile
-----------------------------------------------

.. versionadded:: 2.7

pytest determines a "rootdir" for each test run which depends on
pytest determines a ``rootdir`` for each test run which depends on
the command line arguments (specified test files, paths) and on
the existence of inifiles. The determined rootdir and ini-file are
printed as part of the pytest header. The rootdir is used for constructing
"nodeids" during collection and may also be used by plugins to store
project/testrun-specific information.
the existence of *ini-files*. The determined ``rootdir`` and *ini-file* are
printed as part of the pytest header during startup.

Here's a summary what ``pytest`` uses ``rootdir`` for:

* Construct *nodeids* during collection; each test is assigned
a unique *nodeid* which is rooted at the ``rootdir`` and takes in account full path,
class name, function name and parametrization (if any).

* Is used by plugins as a stable location to store project/test run specific information;
for example, the internal :ref:`cache <cache>` plugin creates a ``.cache`` subdirectory
in ``rootdir`` to store its cross-test run state.

Important to emphasize that ``rootdir`` is **NOT** used to modify ``sys.path``/``PYTHONPATH`` or
influence how modules are imported. See :ref:`pythonpath` for more details.

Finding the ``rootdir``
~~~~~~~~~~~~~~~~~~~~~~~

Here is the algorithm which finds the rootdir from ``args``:

Expand Down
4 changes: 2 additions & 2 deletions doc/en/example/index.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

.. _examples:

Usages and Examples
===========================================
Examples and customization tricks
=================================

Here is a (growing) list of examples. :ref:`Contact <contact>` us if you
need more examples or have questions. Also take a look at the
Expand Down
2 changes: 1 addition & 1 deletion doc/en/nose.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Supported nose Idioms
* setup and teardown at module/class/method level
* SkipTest exceptions and markers
* setup/teardown decorators
* ``yield``-based tests and their setup
* ``yield``-based tests and their setup (considered deprecated as of pytest 3.0)
* ``__test__`` attribute on modules/classes/functions
* general usage of nose utilities

Expand Down
Loading

0 comments on commit ddf1751

Please sign in to comment.