Skip to content

Commit 8c69d5c

Browse files
authored
Merge pull request #1940 from skylarjhdownes/master
adding documentation about pointing pytest at source files
2 parents c734a2d + f2300fb commit 8c69d5c

File tree

8 files changed

+72
-14
lines changed

8 files changed

+72
-14
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Russel Winder
135135
Ryan Wooden
136136
Samuele Pedroni
137137
Simon Gomizelj
138+
Skylar Downes
138139
Stefan Farmbauer
139140
Stefan Zimmermann
140141
Stefano Taschini

CHANGELOG.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
* Fix exception formatting while importing modules when the exception message
99
contains non-ascii characters (`#2336`_).
1010
Thanks `@fabioz`_ for the report and `@nicoddemus`_ for the PR.
11-
11+
12+
* Added documentation related to issue (`#1937`_)
13+
Thanks `@skylarjhdownes`_ for the PR.
1214

1315
*
1416

@@ -17,10 +19,13 @@
1719
*
1820

1921

22+
23+
.. _@skylarjhdownes: https://github.com/skylarjhdownes
2024
.. _@fabioz: https://github.com/fabioz
2125
.. _@metasyn: https://github.com/metasyn
2226

2327

28+
.. _#1937: https://github.com/pytest-dev/pytest/issues/1937
2429
.. _#2276: https://github.com/pytest-dev/pytest/issues/2276
2530
.. _#2336: https://github.com/pytest-dev/pytest/issues/2336
2631

@@ -292,6 +297,7 @@
292297

293298

294299

300+
295301
3.0.2 (2016-09-01)
296302
==================
297303

doc/en/contents.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Full pytest documentation
1212

1313
getting-started
1414
usage
15+
existingtestsuite
1516
assert
1617
builtin
1718
fixture

doc/en/customize.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ Here is the algorithm which finds the rootdir from ``args``:
4545
matched, it becomes the ini-file and its directory becomes the rootdir.
4646

4747
- 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
48+
directory. This allows the use of pytest in structures that are not part of
4949
a package and don't have any particular ini-file configuration.
5050

5151
If no ``args`` are given, pytest collects test below the current working
52-
directory and also starts determining the rootdir from there.
52+
directory and also starts determining the rootdir from there.
5353

5454
:warning: custom pytest plugin commandline arguments may include a path, as in
5555
``pytest --log-output ../../test.log args``. Then ``args`` is mandatory,
@@ -97,6 +97,8 @@ check for ini-files as follows::
9797
.. _`how to change command line options defaults`:
9898
.. _`adding default options`:
9999

100+
101+
100102
How to change command line options defaults
101103
------------------------------------------------
102104

doc/en/existingtestsuite.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.. _existingtestsuite:
2+
3+
Using pytest with an existing test suite
4+
===========================================
5+
6+
Pytest can be used with most existing test suites, but its
7+
behavior differs from other test runners such as :ref:`nose <noseintegration>` or
8+
Python's default unittest framework.
9+
10+
Before using this section you will want to :ref:`install pytest <getstarted>`.
11+
12+
Running an existing test suite with pytest
13+
---------------------------------------------
14+
15+
Say you want to contribute to an existing repository somewhere.
16+
After pulling the code into your development space using some
17+
flavor of version control and (optionally) setting up a virtualenv
18+
you will want to run::
19+
20+
cd <repository>
21+
pip install -e . # Environment dependent alternatives include
22+
# 'python setup.py develop' and 'conda develop'
23+
24+
in your project root. This will set up a symlink to your code in
25+
site-packages, allowing you to edit your code while your tests
26+
run against it as if it were installed.
27+
28+
Setting up your project in development mode lets you avoid having to
29+
reinstall every time you want to run your tests, and is less brittle than
30+
mucking about with sys.path to point your tests at local code.
31+
32+
Also consider using :ref:`tox <use tox>`.
33+
34+
.. include:: links.inc

doc/en/getting-started.rst

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ That's it. You can execute the test function now::
4949
platform linux -- Python 3.5.2, pytest-3.0.7, py-1.4.32, pluggy-0.4.0
5050
rootdir: $REGENDOC_TMPDIR, inifile:
5151
collected 1 items
52-
52+
5353
test_sample.py F
54-
54+
5555
======= FAILURES ========
5656
_______ test_answer ________
57-
57+
5858
def test_answer():
5959
> assert func(3) == 5
6060
E assert 4 == 5
6161
E + where 4 = func(3)
62-
62+
6363
test_sample.py:5: AssertionError
6464
======= 1 failed in 0.12 seconds ========
6565

@@ -128,15 +128,15 @@ run the module by passing its filename::
128128
.F
129129
======= FAILURES ========
130130
_______ TestClass.test_two ________
131-
131+
132132
self = <test_class.TestClass object at 0xdeadbeef>
133-
133+
134134
def test_two(self):
135135
x = "hello"
136136
> assert hasattr(x, 'check')
137137
E AssertionError: assert False
138138
E + where False = hasattr('hello', 'check')
139-
139+
140140
test_class.py:8: AssertionError
141141
1 failed, 1 passed in 0.12 seconds
142142

@@ -165,14 +165,14 @@ before performing the test function call. Let's just run it::
165165
F
166166
======= FAILURES ========
167167
_______ test_needsfiles ________
168-
168+
169169
tmpdir = local('PYTEST_TMPDIR/test_needsfiles0')
170-
170+
171171
def test_needsfiles(tmpdir):
172172
print (tmpdir)
173173
> assert 0
174174
E assert 0
175-
175+
176176
test_tmpdir.py:3: AssertionError
177177
--------------------------- Captured stdout call ---------------------------
178178
PYTEST_TMPDIR/test_needsfiles0
@@ -192,6 +192,7 @@ Here are a few suggestions where to go next:
192192

193193
* :ref:`cmdline` for command line invocation examples
194194
* :ref:`good practices <goodpractices>` for virtualenv, test layout
195+
* :ref:`existingtestsuite` for working with pre-existing tests
195196
* :ref:`fixtures` for providing a functional baseline to your tests
196197
* :ref:`plugins` managing and writing plugins
197198

doc/en/goodpractices.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ You can then install your package in "editable" mode::
187187
pip install -e .
188188

189189
which lets you change your source code (both tests and application) and rerun tests at will.
190+
This is similar to running `python setup.py develop` or `conda develop` in that it installs
191+
your package using a symlink to your development code.
190192

191193
Once you are done with your work and want to make sure that your actual
192194
package passes all tests you may want to look into `tox`_, the

doc/en/nose.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,19 @@ Unsupported idioms / known issues
4747
``tests.test_mod``) but different file system paths
4848
(e.g. ``tests/test_mode.py`` and ``other/tests/test_mode.py``)
4949
by extending sys.path/import semantics. pytest does not do that
50-
but there is discussion in `issue268 <https://github.com/pytest-dev/pytest/issues/268>`_ for adding some support. Note that
50+
but there is discussion in `#268 <https://github.com/pytest-dev/pytest/issues/268>`_ for adding some support. Note that
5151
`nose2 choose to avoid this sys.path/import hackery <https://nose2.readthedocs.io/en/latest/differences.html#test-discovery-and-loading>`_.
5252

53+
If you place a conftest.py file in the root directory of your project
54+
(as determined by pytest) pytest will run tests "nose style" against
55+
the code below that directory by adding it to your ``sys.path`` instead of
56+
running against your installed code.
57+
58+
You may find yourself wanting to do this if you ran ``python setup.py install``
59+
to set up your project, as opposed to ``python setup.py develop`` or any of
60+
the package manager equivalents. Installing with develop in a
61+
virtual environment like Tox is recommended over this pattern.
62+
5363
- nose-style doctests are not collected and executed correctly,
5464
also doctest fixtures don't work.
5565

@@ -62,3 +72,4 @@ Unsupported idioms / known issues
6272
being the recommended alternative.
6373

6474

75+

0 commit comments

Comments
 (0)