Skip to content

Commit 9f78760

Browse files
committed
Merge branch 'documentation'.
2 parents ccb0848 + 0de07ad commit 9f78760

File tree

13 files changed

+379
-65
lines changed

13 files changed

+379
-65
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
** New features
77

8+
+ Issue #2: Add documentation.
9+
810
+ Issue #4: Add a depend() function to add a dependency to a test at
911
runtime.
1012

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ include CHANGES
22
include LICENSE.txt
33
include MANIFEST.in
44
include README.rst
5+
include doc/examples/*.py
56
include doc/html/*.html
67
include doc/html/*.js
78
include doc/html/_static/*

README.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ It removes the use of certain language features (dict comprehensions)
5454
that were introduced in Python 2.7.
5555

5656

57+
Documentation
58+
-------------
59+
60+
The directory doc/html in the source distribution contains the
61+
documentation in HTML form generated by Sphinx. The starting point is
62+
doc/html/index.html. The documentation can also be found online at
63+
64+
http://pythonhosted.org/pytest-dependency/
65+
66+
The example test modules used in the documentation can be found in
67+
doc/examples in the source distribution.
68+
69+
5770
Bugs and limitations
5871
--------------------
5972

doc/examples/basic.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
3+
@pytest.mark.dependency()
4+
@pytest.mark.xfail(reason="deliberate fail")
5+
def test_a():
6+
assert False
7+
8+
@pytest.mark.dependency()
9+
def test_b():
10+
pass
11+
12+
@pytest.mark.dependency(depends=["test_a"])
13+
def test_c():
14+
pass
15+
16+
@pytest.mark.dependency(depends=["test_b"])
17+
def test_d():
18+
pass
19+
20+
@pytest.mark.dependency(depends=["test_b", "test_c"])
21+
def test_e():
22+
pass

doc/examples/named.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
3+
@pytest.mark.dependency(name="a")
4+
@pytest.mark.xfail(reason="deliberate fail")
5+
def test_a():
6+
assert False
7+
8+
@pytest.mark.dependency(name="b")
9+
def test_b():
10+
pass
11+
12+
@pytest.mark.dependency(name="c", depends=["a"])
13+
def test_c():
14+
pass
15+
16+
@pytest.mark.dependency(name="d", depends=["b"])
17+
def test_d():
18+
pass
19+
20+
@pytest.mark.dependency(name="e", depends=["b", "c"])
21+
def test_e():
22+
pass

doc/examples/parametrized.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pytest
2+
3+
@pytest.mark.parametrize("x,y", [
4+
pytest.mark.dependency(name="a1")((0,0)),
5+
pytest.mark.dependency(name="a2")(pytest.mark.xfail((0,1))),
6+
pytest.mark.dependency(name="a3")((1,0)),
7+
pytest.mark.dependency(name="a4")((1,1))
8+
])
9+
def test_a(x,y):
10+
assert y <= x
11+
12+
@pytest.mark.parametrize("u,v", [
13+
pytest.mark.dependency(name="b1", depends=["a1", "a2"])((1,2)),
14+
pytest.mark.dependency(name="b2", depends=["a1", "a3"])((1,3)),
15+
pytest.mark.dependency(name="b3", depends=["a1", "a4"])((1,4)),
16+
pytest.mark.dependency(name="b4", depends=["a2", "a3"])((2,3)),
17+
pytest.mark.dependency(name="b5", depends=["a2", "a4"])((2,4)),
18+
pytest.mark.dependency(name="b6", depends=["a3", "a4"])((3,4))
19+
])
20+
def test_b(u,v):
21+
pass
22+
23+
@pytest.mark.parametrize("w", [
24+
pytest.mark.dependency(name="c1", depends=["b1", "b2", "b6"])(1),
25+
pytest.mark.dependency(name="c2", depends=["b2", "b3", "b6"])(2),
26+
pytest.mark.dependency(name="c3", depends=["b2", "b4", "b6"])(3)
27+
])
28+
def test_c(w):
29+
pass

doc/examples/runtime.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
from pytest_dependency import depends
3+
4+
@pytest.mark.dependency()
5+
def test_a():
6+
pass
7+
8+
@pytest.mark.dependency()
9+
@pytest.mark.xfail(reason="deliberate fail")
10+
def test_b():
11+
assert False
12+
13+
@pytest.mark.dependency()
14+
def test_c(request):
15+
depends(request, ["test_b"])
16+
pass
17+
18+
@pytest.mark.dependency()
19+
def test_d(request):
20+
depends(request, ["test_a", "test_c"])
21+
pass

doc/src/about.rst

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
About pytest-dependency
2+
=======================
3+
4+
This module is a plugin for the popular Python testing framework
5+
`pytest`_. It manages dependencies of tests: you may mark some tests
6+
as dependent from other tests. These tests will then be skipped if
7+
any of the dependencies did fail or has been skipped.
8+
9+
10+
What is the purpose?
11+
--------------------
12+
13+
In the theory of good test design, tests should be self-contained and
14+
independent. Each test should cover one single issue, either verify
15+
that one single feature is working or that one single bug is fixed.
16+
Tests should be designed to work in any order independent of each
17+
other.
18+
19+
So far the theory. The practice is often more complicated then that.
20+
Sometimes, the principle of independency of tests is simply
21+
unrealistic or impractical. Program features often depend on each
22+
other. If some feature B depends on another feature A in such a way
23+
that B cannot work without A, then it may simply be pointless to run
24+
the test for B unless the test for A has succeeded. Another case may
25+
be if the subject of the tests has an internal state that unavoidably
26+
is influenced by the tests. In this situation it may happen that test
27+
A, as a side effect, sets the system in some state that is the
28+
precondition to be able to run test B. Again, in this case it would
29+
be pointless to try running test B unless test A has been run
30+
successful.
31+
32+
It should be emphasized however that the principle of independency of
33+
tests is still valid. Before using pytest-dependency, it is still
34+
advisable to reconsider your test design and to avoid dependencies of
35+
tests whenever possible, rather then to manage these dependencies.
36+
37+
38+
How does it work?
39+
-----------------
40+
41+
The pytest-dependency module defines a marker that can be applied to
42+
tests. The marker accepts an argument that allows to list the
43+
dependencies of the test. Both tests, the dependency and the
44+
dependent test should be decorated with the marker. Behind the
45+
scenes, the marker arranges for the result of the test to be recorded
46+
internally. If a list of dependencies has been given as argument, the
47+
marker verifies that a successful outcome of all the dependencies has
48+
been registered previously and causes a skip of the test if this was
49+
not the case.
50+
51+
52+
Why is this useful?
53+
-------------------
54+
55+
The benefit of skipping dependent tests is the same as for skipping
56+
tests in general: it avoids cluttering the test report with useless
57+
and misleading failure reports from tests that have been known
58+
beforehand not to work in this particular case.
59+
60+
If tests depend on each other in such a way that test B cannot work
61+
unless test A has been run successfully, a failure of test A will
62+
likely result in failure messages from both tests. But the failure
63+
message from test B will not be helpful in any way. It will only
64+
distract the user from the real issue that is the failure of test A.
65+
Skipping test B in this case will help the user to concentrate on
66+
those results that really matter.
67+
68+
69+
Copyright and License
70+
---------------------
71+
72+
- Copyright 2013-2015
73+
Helmholtz-Zentrum Berlin für Materialien und Energie GmbH
74+
- Copyright 2016-2017 Rolf Krahl
75+
76+
Licensed under the Apache License, Version 2.0 (the "License"); you
77+
may not use this file except in compliance with the License. You may
78+
obtain a copy of the License at
79+
80+
http://www.apache.org/licenses/LICENSE-2.0
81+
82+
Unless required by applicable law or agreed to in writing, software
83+
distributed under the License is distributed on an "AS IS" BASIS,
84+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
85+
implied. See the License for the specific language governing
86+
permissions and limitations under the License.
87+
88+
89+
.. _pytest: http://pytest.org/

doc/src/conf.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
# serve to show the default.
1111

1212
import sys, os
13+
import os.path
14+
15+
# Add the top source directory to the module path. This file is
16+
# exec'ed with its directory as cwd. This is "doc/src" relativ to the
17+
# top source directory. So we need to go 2 dirs up.
18+
sys.path.insert(0,os.path.dirname(os.path.dirname(os.getcwd())))
1319

1420
# If extensions (or modules to document with autodoc) are in another directory,
1521
# add these directories to sys.path here. If the directory is relative to the
@@ -39,7 +45,7 @@
3945

4046
# General information about the project.
4147
project = u'pytest-dependency'
42-
copyright = u'2016, Rolf Krahl'
48+
copyright = u'2016-2017, Rolf Krahl'
4349

4450
# The version info for the project you're documenting, acts as replacement for
4551
# |version| and |release|, also used in various other places throughout the

doc/src/index.rst

Lines changed: 8 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,69 +5,13 @@ This pytest plugin manages dependencies of tests. It allows to mark
55
some tests as dependent from other tests. These tests will then be
66
skipped if any of the dependencies did fail or has been skipped.
77

8-
Note that there is no real documentation yet, this just repeats the
9-
content of the README file.
8+
Content of the documentation
9+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1010

11+
.. toctree::
12+
:maxdepth: 2
1113

12-
System requirements
13-
-------------------
14-
15-
+ Python 2.6, 2.7, or 3.1 and newer.
16-
Python 2.6 requires patching the sources, see below.
17-
+ `setuptools`_.
18-
+ `pytest`_ 2.8.0 or newer.
19-
20-
21-
Installation
22-
------------
23-
24-
1. Download the sources, unpack, and change into the source directory.
25-
26-
2. Build (optional)::
27-
28-
$ python setup.py build
29-
30-
3. Test (optional)::
31-
32-
$ python -m pytest
33-
34-
4. Install::
35-
36-
$ python setup.py install
37-
38-
The last step might require admin privileges in order to write into
39-
the site-packages directory of your Python installation.
40-
41-
If you are using Python 2.6, apply python2_6.patch after the first
42-
step:
43-
44-
1a. Patch::
45-
46-
$ patch -p1 < python2_6.patch
47-
48-
It removes the use of certain language features (dict comprehensions)
49-
that were introduced in Python 2.7.
50-
51-
52-
Copyright and License
53-
---------------------
54-
55-
- Copyright 2013-2015
56-
Helmholtz-Zentrum Berlin für Materialien und Energie GmbH
57-
- Copyright 2016-2017 Rolf Krahl
58-
59-
Licensed under the Apache License, Version 2.0 (the "License"); you
60-
may not use this file except in compliance with the License. You may
61-
obtain a copy of the License at
62-
63-
http://www.apache.org/licenses/LICENSE-2.0
64-
65-
Unless required by applicable law or agreed to in writing, software
66-
distributed under the License is distributed on an "AS IS" BASIS,
67-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
68-
implied. See the License for the specific language governing
69-
permissions and limitations under the License.
70-
71-
72-
.. _setuptools: http://pypi.python.org/pypi/setuptools/
73-
.. _pytest: http://pytest.org/
14+
about
15+
install
16+
usage
17+
reference

0 commit comments

Comments
 (0)