Skip to content

Commit 4ab2e57

Browse files
authored
Merge pull request #1797 from nicoddemus/merge-master-into-features
Merge master into features
2 parents 6759b04 + 802755c commit 4ab2e57

21 files changed

+185
-188
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ env:
2525
- TESTENV=py35-trial
2626
- TESTENV=py27-nobyte
2727
- TESTENV=doctesting
28-
- TESTENV=py27-cxfreeze
28+
- TESTENV=freeze
2929

3030
script: tox --recreate -e $TESTENV
3131

CHANGELOG.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ time or change existing behaviors in order to make them less surprising/more use
254254

255255
* ``optparse`` backward compatibility supports float/complex types (`#457`_).
256256

257+
* Refined logic for determining the ``rootdir``, considering only valid
258+
paths which fixes a number of issues: `#1594`_, `#1435`_ and `#1471`_.
259+
Thanks to `@blueyed`_ and `@davehunt`_ for the PR.
260+
261+
* Always include full assertion explanation. The previous behaviour was hiding
262+
sub-expressions that happened to be False, assuming this was redundant information.
263+
Thanks `@bagerard`_ for reporting (`#1503`_). Thanks to `@davehunt`_ and
264+
`@tomviner`_ for PR.
265+
257266
* Renamed the pytest ``pdb`` module (plugin) into ``debugging``.
258267

259268
* Better message in case of not using parametrized variable (see `#1539`_).
@@ -322,11 +331,13 @@ time or change existing behaviors in order to make them less surprising/more use
322331
.. _#1421: https://github.com/pytest-dev/pytest/issues/1421
323332
.. _#1426: https://github.com/pytest-dev/pytest/issues/1426
324333
.. _#1428: https://github.com/pytest-dev/pytest/pull/1428
334+
.. _#1435: https://github.com/pytest-dev/pytest/issues/1435
325335
.. _#1441: https://github.com/pytest-dev/pytest/pull/1441
326336
.. _#1444: https://github.com/pytest-dev/pytest/pull/1444
327337
.. _#1454: https://github.com/pytest-dev/pytest/pull/1454
328338
.. _#1461: https://github.com/pytest-dev/pytest/pull/1461
329339
.. _#1468: https://github.com/pytest-dev/pytest/pull/1468
340+
.. _#1471: https://github.com/pytest-dev/pytest/issues/1471
330341
.. _#1474: https://github.com/pytest-dev/pytest/pull/1474
331342
.. _#1479: https://github.com/pytest-dev/pytest/issues/1479
332343
.. _#1502: https://github.com/pytest-dev/pytest/pull/1502
@@ -341,6 +352,7 @@ time or change existing behaviors in order to make them less surprising/more use
341352
.. _#1562: https://github.com/pytest-dev/pytest/issues/1562
342353
.. _#1579: https://github.com/pytest-dev/pytest/issues/1579
343354
.. _#1580: https://github.com/pytest-dev/pytest/pull/1580
355+
.. _#1594: https://github.com/pytest-dev/pytest/issues/1594
344356
.. _#1597: https://github.com/pytest-dev/pytest/pull/1597
345357
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605
346358
.. _#1616: https://github.com/pytest-dev/pytest/pull/1616
@@ -367,6 +379,7 @@ time or change existing behaviors in order to make them less surprising/more use
367379
.. _#717: https://github.com/pytest-dev/pytest/issues/717
368380
.. _#925: https://github.com/pytest-dev/pytest/issues/925
369381

382+
370383
.. _@anntzer: https://github.com/anntzer
371384
.. _@bagerard: https://github.com/bagerard
372385
.. _@BeyondEvil: https://github.com/BeyondEvil
@@ -397,8 +410,8 @@ time or change existing behaviors in order to make them less surprising/more use
397410
.. _@RedBeardCode: https://github.com/RedBeardCode
398411
.. _@sallner: https://github.com/sallner
399412
.. _@sober7: https://github.com/sober7
400-
.. _@suzaku: https://github.com/suzaku
401413
.. _@Stranger6667: https://github.com/Stranger6667
414+
.. _@suzaku: https://github.com/suzaku
402415
.. _@tareqalayan: https://github.com/tareqalayan
403416
.. _@taschini: https://github.com/taschini
404417
.. _@tramwaj29: https://github.com/tramwaj29

README.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
.. image:: http://pytest.org/latest/_static/pytest1.png
2-
:target: http://pytest.org
1+
.. image:: http://docs.pytest.org/en/latest/_static/pytest1.png
2+
:target: http://docs.pytest.org
33
:align: center
44
:alt: pytest
55

@@ -51,33 +51,34 @@ To execute it::
5151
test_sample.py:5: AssertionError
5252
======= 1 failed in 0.12 seconds ========
5353

54-
Due to ``pytest``'s detailed assertion introspection, only plain ``assert`` statements are used. See `getting-started <http://pytest.org/latest/getting-started.html#our-first-test-run>`_ for more examples.
54+
55+
Due to ``py.test``'s detailed assertion introspection, only plain ``assert`` statements are used. See `getting-started <http://docs.pytest.org/en/latest/getting-started.html#our-first-test-run>`_ for more examples.
5556

5657

5758
Features
5859
--------
5960

60-
- Detailed info on failing `assert statements <http://pytest.org/latest/assert.html>`_ (no need to remember ``self.assert*`` names);
61+
- Detailed info on failing `assert statements <http://docs.pytest.org/en/latest/assert.html>`_ (no need to remember ``self.assert*`` names);
6162

6263
- `Auto-discovery
63-
<http://pytest.org/latest/goodpractices.html#python-test-discovery>`_
64+
<http://docs.pytest.org/en/latest/goodpractices.html#python-test-discovery>`_
6465
of test modules and functions;
6566

66-
- `Modular fixtures <http://pytest.org/latest/fixture.html>`_ for
67+
- `Modular fixtures <http://docs.pytest.org/en/latest/fixture.html>`_ for
6768
managing small or parametrized long-lived test resources;
6869

69-
- Can run `unittest <http://pytest.org/latest/unittest.html>`_ (or trial),
70-
`nose <http://pytest.org/latest/nose.html>`_ test suites out of the box;
70+
- Can run `unittest <http://docs.pytest.org/en/latest/unittest.html>`_ (or trial),
71+
`nose <http://docs.pytest.org/en/latest/nose.html>`_ test suites out of the box;
7172

7273
- Python2.6+, Python3.3+, PyPy-2.3, Jython-2.5 (untested);
7374

74-
- Rich plugin architecture, with over 150+ `external plugins <http://pytest.org/latest/plugins.html#installing-external-plugins-searching>`_ and thriving community;
75+
- Rich plugin architecture, with over 150+ `external plugins <http://docs.pytest.org/en/latest/plugins.html#installing-external-plugins-searching>`_ and thriving community;
7576

7677

7778
Documentation
7879
-------------
7980

80-
For full documentation, including installation, tutorials and PDF documents, please see http://pytest.org.
81+
For full documentation, including installation, tutorials and PDF documents, please see http://docs.pytest.org.
8182

8283

8384
Bugs/Requests
@@ -89,7 +90,7 @@ Please use the `GitHub issue tracker <https://github.com/pytest-dev/pytest/issue
8990
Changelog
9091
---------
9192

92-
Consult the `Changelog <http://pytest.org/latest/changelog.html>`_ page for fixes and enhancements of each version.
93+
Consult the `Changelog <http://docs.pytest.org/en/latest/changelog.html>`_ page for fixes and enhancements of each version.
9394

9495

9596
License

_pytest/config.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,8 @@ def get_common_ancestor(args):
11811181
if str(arg)[0] == "-":
11821182
continue
11831183
p = py.path.local(arg)
1184+
if not p.exists():
1185+
continue
11841186
if common_ancestor is None:
11851187
common_ancestor = p
11861188
else:
@@ -1194,29 +1196,42 @@ def get_common_ancestor(args):
11941196
common_ancestor = shared
11951197
if common_ancestor is None:
11961198
common_ancestor = py.path.local()
1197-
elif not common_ancestor.isdir():
1199+
elif common_ancestor.isfile():
11981200
common_ancestor = common_ancestor.dirpath()
11991201
return common_ancestor
12001202

12011203

1204+
def get_dirs_from_args(args):
1205+
return [d for d in (py.path.local(x) for x in args
1206+
if not str(x).startswith("-"))
1207+
if d.exists()]
1208+
1209+
12021210
def determine_setup(inifile, args):
1211+
dirs = get_dirs_from_args(args)
12031212
if inifile:
12041213
iniconfig = py.iniconfig.IniConfig(inifile)
12051214
try:
12061215
inicfg = iniconfig["pytest"]
12071216
except KeyError:
12081217
inicfg = None
1209-
rootdir = get_common_ancestor(args)
1218+
rootdir = get_common_ancestor(dirs)
12101219
else:
1211-
ancestor = get_common_ancestor(args)
1220+
ancestor = get_common_ancestor(dirs)
12121221
rootdir, inifile, inicfg = getcfg(
12131222
[ancestor], ["pytest.ini", "tox.ini", "setup.cfg"])
12141223
if rootdir is None:
12151224
for rootdir in ancestor.parts(reverse=True):
12161225
if rootdir.join("setup.py").exists():
12171226
break
12181227
else:
1219-
rootdir = ancestor
1228+
rootdir, inifile, inicfg = getcfg(
1229+
dirs, ["pytest.ini", "tox.ini", "setup.cfg"])
1230+
if rootdir is None:
1231+
rootdir = get_common_ancestor([py.path.local(), ancestor])
1232+
is_fs_root = os.path.splitdrive(str(rootdir))[1] == os.sep
1233+
if is_fs_root:
1234+
rootdir = ancestor
12201235
return rootdir, inifile, inicfg or {}
12211236

12221237

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ environment:
1010
# builds timing out in AppVeyor
1111
- TOXENV: "linting,py26,py27,py33,py34,py35,pypy"
1212
- TOXENV: "py27-pexpect,py27-xdist,py27-trial,py35-pexpect,py35-xdist,py35-trial"
13-
- TOXENV: "py27-nobyte,doctesting,py27-cxfreeze"
13+
- TOXENV: "py27-nobyte,doctesting,freeze"
1414

1515
install:
1616
- echo Installed Pythons

doc/en/contents.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Full pytest documentation
44
===========================
55

6-
`Download latest version as PDF <pytest.pdf>`_
6+
`Download latest version as PDF <https://media.readthedocs.org/pdf/pytest/latest/pytest.pdf>`_
77

88
.. `Download latest version as EPUB <http://media.readthedocs.org/epub/pytest/latest/pytest.epub>`_
99

doc/en/customize.rst

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,29 @@ project/testrun-specific information.
2929

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

32-
- determine the common ancestor directory for the specified ``args``.
32+
- determine the common ancestor directory for the specified ``args`` that are
33+
recognised as paths that exist in the file system. If no such paths are
34+
found, the common ancestor directory is set to the current working directory.
3335

34-
- look for ``pytest.ini``, ``tox.ini`` and ``setup.cfg`` files in the
35-
ancestor directory and upwards. If one is matched, it becomes the
36-
ini-file and its directory becomes the rootdir. An existing
37-
``pytest.ini`` file will always be considered a match whereas
38-
``tox.ini`` and ``setup.cfg`` will only match if they contain
39-
a ``[pytest]`` section.
36+
- look for ``pytest.ini``, ``tox.ini`` and ``setup.cfg`` files in the ancestor
37+
directory and upwards. If one is matched, it becomes the ini-file and its
38+
directory becomes the rootdir.
4039

41-
- if no ini-file was found, look for ``setup.py`` upwards from
42-
the common ancestor directory to determine the ``rootdir``.
40+
- if no ini-file was found, look for ``setup.py`` upwards from the common
41+
ancestor directory to determine the ``rootdir``.
4342

44-
- if no ini-file and no ``setup.py`` was found, use the already
45-
determined common ancestor as root directory. This allows to
46-
work with pytest in structures that are not part of a package
47-
and don't have any particular ini-file configuration.
43+
- if no ``setup.py`` was found, look for ``pytest.ini``, ``tox.ini`` and
44+
``setup.cfg`` in each of the specified ``args`` and upwards. If one is
45+
matched, it becomes the ini-file and its directory becomes the rootdir.
4846

49-
Note that options from multiple ini-files candidates are never merged,
50-
the first one wins (``pytest.ini`` always wins even if it does not
47+
- if no ini-file was found, use the already determined common ancestor as root
48+
directory. This allows to work with pytest in structures that are not part of
49+
a package and don't have any particular ini-file configuration.
50+
51+
Note that an existing ``pytest.ini`` file will always be considered a match,
52+
whereas ``tox.ini`` and ``setup.cfg`` will only match if they contain a
53+
``[pytest]`` section. Options from multiple ini-files candidates are never
54+
merged - the first one wins (``pytest.ini`` always wins, even if it does not
5155
contain a ``[pytest]`` section).
5256

5357
The ``config`` object will subsequently carry these attributes:

doc/en/example/simple.rst

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -720,40 +720,29 @@ and run it::
720720
You'll see that the fixture finalizers could use the precise reporting
721721
information.
722722

723-
Integrating pytest runner and cx_freeze
724-
-----------------------------------------------------------
723+
Freezing pytest
724+
---------------
725725

726726
If you freeze your application using a tool like
727-
`cx_freeze <https://cx-freeze.readthedocs.io>`_ in order to distribute it
728-
to your end-users, it is a good idea to also package your test runner and run
729-
your tests using the frozen application.
730-
731-
This way packaging errors such as dependencies not being
732-
included into the executable can be detected early while also allowing you to
733-
send test files to users so they can run them in their machines, which can be
734-
invaluable to obtain more information about a hard to reproduce bug.
735-
736-
Unfortunately ``cx_freeze`` can't discover them
737-
automatically because of ``pytest``'s use of dynamic module loading, so you
738-
must declare them explicitly by using ``pytest.freeze_includes()``::
739-
740-
# contents of setup.py
741-
from cx_Freeze import setup, Executable
742-
import pytest
743-
744-
setup(
745-
name="app_main",
746-
executables=[Executable("app_main.py")],
747-
options={"build_exe":
748-
{
749-
'includes': pytest.freeze_includes()}
750-
},
751-
# ... other options
752-
)
753-
754-
If you don't want to ship a different executable just in order to run your tests,
755-
you can make your program check for a certain flag and pass control
756-
over to ``pytest`` instead. For example::
727+
`PyInstaller <https://pyinstaller.readthedocs.io>`_
728+
in order to distribute it to your end-users, it is a good idea to also package
729+
your test runner and run your tests using the frozen application. This way packaging
730+
errors such as dependencies not being included into the executable can be detected early
731+
while also allowing you to send test files to users so they can run them in their
732+
machines, which can be useful to obtain more information about a hard to reproduce bug.
733+
734+
Fortunately recent ``PyInstaller`` releases already have a custom hook
735+
for pytest, but if you are using another tool to freeze executables
736+
such as ``cx_freeze`` or ``py2exe``, you can use ``pytest.freeze_includes()``
737+
to obtain the full list of internal pytest modules. How to configure the tools
738+
to find the internal modules varies from tool to tool, however.
739+
740+
Instead of freezing the pytest runner as a separate executable, you can make
741+
your frozen program work as the pytest runner by some clever
742+
argument handling during program startup. This allows you to
743+
have a single executable, which is usually more convenient.
744+
745+
.. code-block:: python
757746
758747
# contents of app_main.py
759748
import sys
@@ -766,7 +755,8 @@ over to ``pytest`` instead. For example::
766755
# by your argument-parsing library of choice as usual
767756
...
768757
769-
This makes it convenient to execute your tests from within your frozen
770-
application, using standard ``pytest`` command-line options::
758+
759+
This allows you to execute tests using the frozen
760+
application with standard ``pytest`` command-line options::
771761

772762
./app_main --pytest --verbose --tb=long --junitxml=results.xml test-suite/

doc/en/getting-started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Installation and Getting Started
1111
`colorama (Windows) <http://pypi.python.org/pypi/colorama>`_,
1212
`argparse (py26) <http://pypi.python.org/pypi/argparse>`_.
1313

14-
**documentation as PDF**: `download latest <http://pytest.org/latest/pytest.pdf>`_
14+
**documentation as PDF**: `download latest <https://media.readthedocs.org/pdf/pytest/latest/pytest.pdf>`_
1515

1616
.. _`getstarted`:
1717
.. _installation:

doc/en/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pytest: helps you write better programs
1010
- free and open source software, distributed under the terms of the :ref:`MIT license <license>`
1111
- **well tested** with more than a thousand tests against itself
1212
- **strict backward compatibility policy** for safe pytest upgrades
13-
- :ref:`comprehensive online <toc>` and `PDF documentation <pytest.pdf>`_
13+
- :ref:`comprehensive online <toc>` and `PDF documentation <https://media.readthedocs.org/pdf/pytest/latest/pytest.pdf>`_
1414
- many :ref:`third party plugins <extplugins>` and :ref:`builtin helpers <pytest helpers>`,
1515
- used in :ref:`many small and large projects and organisations <projects>`
1616
- comes with many :ref:`tested examples <examples>`

testing/cx_freeze/install_cx_freeze.py

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)