Skip to content

Commit 4a16d8d

Browse files
committed
Add order-scope option
- allows to use module or class scoped ordering - also replace ' by ", as black prefers this - closes #2
1 parent 47d1d0d commit 4a16d8d

19 files changed

+378
-202
lines changed

.github/workflows/builddocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
run: |
4646
cp -r main/docs/build/html/* doc/dev
4747
cd doc
48-
git config user.name "Travis CI"
48+
git config user.name "CI Build"
4949
git config user.email "[email protected]"
5050
git add dev/*
5151
if [ `git status -s | wc -l` = 0 ]; then

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Added
6+
- add configuration option for sorting scope,
7+
see [#2](https://github.com/mrbean-bremen/pytest-order/issues/2)
8+
59
## [Version 0.8.0](https://pypi.org/project/pytest-order/0.8.0/)
610
This release is mostly related to the consolidation of infrastructure
711
(documentation build and tests in CI build) and documentation.

docs/source/conf.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,36 @@
2727
# -- General configuration ------------------------------------------------
2828

2929
# If your documentation needs a minimal Sphinx version, state it here.
30-
# needs_sphinx = '1.0'
30+
# needs_sphinx = "1.0"
3131

3232
# Add any Sphinx extension module names here, as strings. They can be
33-
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
33+
# extensions coming with Sphinx (named "sphinx.ext.*") or your custom
3434
# ones.
3535
extensions = [
36-
'sphinx.ext.autodoc',
37-
'sphinx.ext.doctest',
38-
'sphinx.ext.coverage',
39-
'sphinx.ext.viewcode',
40-
'sphinx.ext.githubpages', # puts .nojekyll file into source
36+
"sphinx.ext.autodoc",
37+
"sphinx.ext.doctest",
38+
"sphinx.ext.coverage",
39+
"sphinx.ext.viewcode",
40+
"sphinx.ext.githubpages", # puts .nojekyll file into source
4141
]
4242

4343
# Add any paths that contain templates here, relative to this directory.
44-
templates_path = ['_templates']
44+
templates_path = ["_templates"]
4545

4646
# The suffix of source filenames.
47-
source_suffix = '.rst'
47+
source_suffix = ".rst"
4848

4949
# The encoding of source files.
50-
# source_encoding = 'utf-8-sig'
50+
# source_encoding = "utf-8-sig"
5151

5252
# The master toctree document.
53-
master_doc = 'index'
53+
master_doc = "index"
5454

5555
# General information about the project.
56-
project = u'pytest-order'
57-
copyright = u'2014, Frank Tobia'
56+
project = u"pytest-order"
57+
copyright = u"2014, Frank Tobia"
5858

59-
# The version info for the project you're documenting, acts as replacement for
59+
# The version info for the project you"re documenting, acts as replacement for
6060
# |version| and |release|, also used in various other places throughout the
6161
# built documents.
6262
#
@@ -72,9 +72,9 @@
7272

7373
# There are two options for replacing |today|: either, you set today to some
7474
# non-false value, then it is used:
75-
# today = ''
75+
# today = ""
7676
# Else, today_fmt is used as the format for a strftime call.
77-
# today_fmt = '%B %d, %Y'
77+
# today_fmt = "%B %d, %Y"
7878

7979
# List of patterns, relative to source directory, that match files and
8080
# directories to ignore when looking for source files.
@@ -84,7 +84,7 @@
8484
# documents.
8585
# default_role = None
8686

87-
# If true, '()' will be appended to :func: etc. cross-reference text.
87+
# If true, "()" will be appended to :func: etc. cross-reference text.
8888
# add_function_parentheses = True
8989

9090
# If true, the current module name will be prepended to all description
@@ -96,7 +96,7 @@
9696
# show_authors = False
9797

9898
# The name of the Pygments (syntax highlighting) style to use.
99-
pygments_style = 'sphinx'
99+
pygments_style = "sphinx"
100100

101101
# A list of ignored prefixes for module index sorting.
102102
# modindex_common_prefix = []
@@ -109,7 +109,7 @@
109109

110110
# The theme to use for HTML and HTML Help pages. See the documentation for
111111
# a list of builtin themes.
112-
html_theme = 'nature'
112+
html_theme = "nature"
113113

114114
# Theme options are theme-specific and customize the look and feel of a theme
115115
# further. For a list of options available for each theme, see the
@@ -145,9 +145,9 @@
145145
# directly to the root of the documentation.
146146
# html_extra_path = []
147147

148-
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
148+
# If not "", a "Last updated on:" timestamp is inserted at every page bottom,
149149
# using the given strftime format.
150-
# html_last_updated_fmt = '%b %d, %Y'
150+
# html_last_updated_fmt = "%b %d, %Y"
151151

152152
# If true, SmartyPants will be used to convert quotes and dashes to
153153
# typographically correct entities.
@@ -181,33 +181,33 @@
181181
# If true, an OpenSearch description file will be output, and all pages will
182182
# contain a <link> tag referring to it. The value of this option must be the
183183
# base URL from which the finished HTML is served.
184-
# html_use_opensearch = ''
184+
# html_use_opensearch = ""
185185

186186
# This is the file name suffix for HTML files (e.g. ".xhtml").
187187
# html_file_suffix = None
188188

189189
# Output file base name for HTML help builder.
190-
htmlhelp_basename = 'pytest-orderdoc'
190+
htmlhelp_basename = "pytest-orderdoc"
191191

192192
# -- Options for LaTeX output ---------------------------------------------
193193

194194
latex_elements = {
195-
# The paper size ('letterpaper' or 'a4paper').
196-
# 'papersize': 'letterpaper',
195+
# The paper size ("letterpaper" or "a4paper").
196+
# "papersize": "letterpaper",
197197

198-
# The font size ('10pt', '11pt' or '12pt').
199-
# 'pointsize': '10pt',
198+
# The font size ("10pt", "11pt" or "12pt").
199+
# "pointsize": "10pt",
200200

201201
# Additional stuff for the LaTeX preamble.
202-
# 'preamble': '',
202+
# "preamble": "",
203203
}
204204

205205
# Grouping the document tree into LaTeX files. List of tuples
206206
# (source start file, target name, title,
207207
# author, documentclass [howto, manual, or own class]).
208208
latex_documents = [
209-
('index', 'pytest-order.tex', u'pytest-order Documentation',
210-
u'Frank Tobia', 'manual'),
209+
("index", "pytest-order.tex", u"pytest-order Documentation",
210+
u"Frank Tobia", "manual"),
211211
]
212212

213213
# The name of an image file (relative to this directory) to place at the top of
@@ -236,8 +236,8 @@
236236
# One entry per manual page. List of tuples
237237
# (source start file, name, description, authors, manual section).
238238
man_pages = [
239-
('index', 'pytest-order', u'pytest-order Documentation',
240-
[u'Frank Tobia'], 1)
239+
("index", "pytest-order", u"pytest-order Documentation",
240+
[u"Frank Tobia"], 1)
241241
]
242242

243243
# If true, show URL addresses after external links.
@@ -250,9 +250,9 @@
250250
# (source start file, target name, title, author,
251251
# dir menu entry, description, category)
252252
texinfo_documents = [
253-
('index', 'pytest-order', u'pytest-order Documentation',
254-
u'Frank Tobia', 'pytest-order', 'One line description of project.',
255-
'Miscellaneous'),
253+
("index", "pytest-order", u"pytest-order Documentation",
254+
u"Frank Tobia", "pytest-order", "One line description of project.",
255+
"Miscellaneous"),
256256
]
257257

258258
# Documents to append as an appendix to all manuals.
@@ -261,8 +261,8 @@
261261
# If false, no module index is generated.
262262
# texinfo_domain_indices = True
263263

264-
# How to display URL addresses: 'footnote', 'no', or 'inline'.
265-
# texinfo_show_urls = 'footnote'
264+
# How to display URL addresses: "footnote", "no", or "inline".
265+
# texinfo_show_urls = "footnote"
266266

267-
# If true, do not generate a @detailmenu in the "Top" node's menu.
267+
# If true, do not generate a @detailmenu in the "Top" node"s menu.
268268
# texinfo_no_detailmenu = False

docs/source/index.rst

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ There are currently three possibilities to define the order:
121121
Order by number
122122
---------------
123123
As already shown above, the order can be defined using ordinal numbers.
124-
Negative numbers are also allowed - they are used the same way as indexes
124+
Negative numbers are also allowed--they are used the same way as indexes
125125
are used in Python lists, e.g. to count from the end:
126126

127127
.. code:: python
@@ -265,7 +265,9 @@ by their name:
265265

266266
Configuration
267267
=============
268-
Currently there is only one option that changes the behavior of the plugin.
268+
Currently there are two command line option that change the behavior of the
269+
plugin. As for any option, you can add the options to your ``pytest.ini`` if
270+
you want to have them always applied.
269271

270272
``--indulgent-ordering``
271273
------------------------
@@ -284,6 +286,24 @@ pytest-order *before* the sort from ``--failed-first``, allowing the failed
284286
tests to be sorted to the front (note that in pytest versions from 6.0 on,
285287
this seems not to be needed anymore, at least in this specific case).
286288

289+
``--order-scope``
290+
-----------------
291+
By default, tests are ordered per session, e.g. across all modules in the
292+
test run. Sometimes, you want to order tests per module or per test class
293+
instead. Consider that you have a growing number of test modules that you
294+
want to run simultaneously, with tests ordered per module. Per default you
295+
would need to make sure that the order numbers increases globally, if you
296+
want to run the test modules consecutively and order the test per module.
297+
298+
If you use the option ``--order-scope=module``, there is no need for this.
299+
You can enumerate your tests starting with 0 or 1 in each module, and the tests
300+
will only be ordered inside each module. Using ``--order-scope=class``
301+
additionally considers test classes--each test class is considered
302+
separately for ordering the tests. If a module has both test classes and
303+
separate test functions, these test functions are handled separately from the
304+
test classes. If a module has no test classes, the effect is the same as
305+
if using ``--order-scope=module``.
306+
287307
Miscellaneous
288308
=============
289309

example/test_ordinals.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import pytest
22

33

4-
@pytest.mark.order('second_to_last')
4+
@pytest.mark.order("second_to_last")
55
def test_three():
66
assert True
77

88

9-
@pytest.mark.order('last')
9+
@pytest.mark.order("last")
1010
def test_four():
1111
assert True
1212

1313

14-
@pytest.mark.order('second')
14+
@pytest.mark.order("second")
1515
def test_two():
1616
assert True
1717

1818

19-
@pytest.mark.order('first')
19+
@pytest.mark.order("first")
2020
def test_one():
2121
assert True

example/test_other.py

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

example/test_quickstart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import pytest
22

33

4-
@pytest.mark.order2
4+
@pytest.mark.order(2)
55
def test_foo():
66
assert True
77

88

9-
@pytest.mark.order1
9+
@pytest.mark.order(1)
1010
def test_bar():
1111
assert True

example/test_relative.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33

4-
@pytest.mark.order(after='test_second')
4+
@pytest.mark.order(after="test_second")
55
def test_third():
66
assert True
77

@@ -10,6 +10,6 @@ def test_second():
1010
assert True
1111

1212

13-
@pytest.mark.order(before='test_second')
13+
@pytest.mark.order(before="test_second")
1414
def test_first():
1515
assert True

fixture/test_classes.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
3+
4+
class Test1:
5+
@pytest.mark.order("last")
6+
def test_two(self):
7+
assert True
8+
9+
@pytest.mark.order("first")
10+
def test_one(self):
11+
assert True
12+
13+
14+
class Test2:
15+
@pytest.mark.order("last")
16+
def test_two(self):
17+
assert True
18+
19+
@pytest.mark.order("first")
20+
def test_one(self):
21+
assert True
22+
23+
24+
@pytest.mark.order("last")
25+
def test_two():
26+
assert True
27+
28+
29+
@pytest.mark.order("first")
30+
def test_one():
31+
assert True

fixture/test_functions1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytest
2+
3+
4+
@pytest.mark.order("last")
5+
def test_two():
6+
assert True
7+
8+
9+
@pytest.mark.order("first")
10+
def test_one():
11+
assert True

0 commit comments

Comments
 (0)