diff --git a/.gitignore b/.gitignore index d084452..2c0c907 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,9 @@ lib lib64 __pycache__ +# PyCharm +.idea + # Virtualenvs env diff --git a/docs/source/index.rst b/docs/source/index.rst index 0f5d3da..64b5be8 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -13,9 +13,9 @@ second-to-last) or relative (i.e. run this test before this other test). .. note :: pytest-ordering is currently alpha-quality software. Notably, some of this documentation may be aspirational in nature. If something - you read here isn't currently implemented, rest assured that I am working - on it (or feel free to ping me: https://github.com/ftobia) - + you read here isn't currently implemented, you can indicate your interest + by filing a github issue (https://github.com/ftobia) or send a pull + request of your own. Quickstart ---------- @@ -51,11 +51,11 @@ With pytest-ordering, you can change the default ordering as follows: import pytest - @pytest.mark.order2 + @pytest.mark.run(order=2) def test_foo(): assert True - @pytest.mark.order1 + @pytest.mark.run(order=1) def test_bar(): assert True @@ -115,32 +115,26 @@ You can also use markers such as "first", "second", "last", and "second_to_last" =========================== 4 passed in 0.02 seconds =========================== -Aspirational -============ - -This section is for functionality I'd like to implement. -Documentation-driven design :) - -Ordinals --------- +By number +--------- .. code:: python import pytest - @pytest.mark.run('second-to-last') + @pytest.mark.run(order=-2) def test_three(): assert True - @pytest.mark.run('last') + @pytest.mark.run(order=-1) def test_four(): assert True - @pytest.mark.run('second') + @pytest.mark.run(order=2) def test_two(): assert True - @pytest.mark.run('first') + @pytest.mark.run(order=1) def test_one(): assert True @@ -160,26 +154,32 @@ Ordinals =========================== 4 passed in 0.02 seconds =========================== -By number ---------- +Aspirational +============ + +This section is for functionality I'd like to implement. +Documentation-driven design :) + +Ordinals +-------- .. code:: python import pytest - @pytest.mark.run(order=-2) + @pytest.mark.run('second-to-last') def test_three(): assert True - @pytest.mark.run(order=-1) + @pytest.mark.run('last') def test_four(): assert True - @pytest.mark.run(order=2) + @pytest.mark.run('second') def test_two(): assert True - @pytest.mark.run(order=1) + @pytest.mark.run('first') def test_one(): assert True diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..ca2d15d --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +import pytest + +pytest_plugins = ['pytester'] + + +@pytest.fixture +def item_names_for(testdir): + + def _item_names_for(tests_content): + # some strange code to extract sorted items + items = testdir.getitems(tests_content) + hook = testdir.config.hook + hook.pytest_collection_modifyitems(session=items[0].session, + config=testdir.config, items=items) + return [item.name for item in items] + + return _item_names_for diff --git a/tests/test_misc.py b/tests/test_misc.py index 5a1a597..9cf8aa9 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import re +import pytest import pytest_ordering @@ -11,3 +12,9 @@ def test_version_exists(): def test_version_valid(): assert re.match(r'[0-9]+\.[0-9]+(\.[0-9]+)?$', pytest_ordering.__version__) + + +def test_run_marker_registered(capsys): + pytest.main('--markers') + out, err = capsys.readouterr() + assert '@pytest.mark.run' in out diff --git a/tests/test_ordering.py b/tests/test_ordering.py index 12f4689..0792a05 100644 --- a/tests/test_ordering.py +++ b/tests/test_ordering.py @@ -1,24 +1,4 @@ # -*- coding: utf-8 -*- -import re - -import pytest - -pytest_plugins = ['pytester'] - - -@pytest.fixture -def item_names_for(testdir): - - def _item_names_for(tests_content): - # some strange code to extract sorted items - items = testdir.getitems(tests_content) - hook = testdir.config.hook - hook.pytest_collection_modifyitems(session=items[0].session, - config=testdir.config, items=items) - return [item.name for item in items] - - return _item_names_for - def test_no_marks(item_names_for): tests_content = """ @@ -30,48 +10,6 @@ def test_2(): pass assert item_names_for(tests_content) == ['test_1', 'test_2'] -def test_first_mark(item_names_for): - tests_content = """ - import pytest - - def test_1(): pass - - @pytest.mark.first - def test_2(): pass - """ - - assert item_names_for(tests_content) == ['test_2', 'test_1'] - - -def test_last_mark(item_names_for): - tests_content = """ - import pytest - - @pytest.mark.last - def test_1(): pass - - def test_2(): pass - """ - - assert item_names_for(tests_content) == ['test_2', 'test_1'] - - -def test_first_last_marks(item_names_for): - tests_content = """ - import pytest - - @pytest.mark.last - def test_1(): pass - - @pytest.mark.first - def test_2(): pass - - def test_3(): pass - """ - - assert item_names_for(tests_content) == ['test_2', 'test_3', 'test_1'] - - def test_order_marks(item_names_for): tests_content = """ import pytest @@ -266,9 +204,3 @@ def test_5(self): pass """ assert item_names_for(tests_content) == ['test_3', 'test_4', 'test_5', 'test_1', 'test_2'] - - -def test_run_marker_registered(capsys): - pytest.main('--markers') - out, err = capsys.readouterr() - assert '@pytest.mark.run' in out diff --git a/tests/test_ordinals.py b/tests/test_ordinals.py new file mode 100644 index 0000000..9116724 --- /dev/null +++ b/tests/test_ordinals.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- + + +def test_first(item_names_for): + tests_content = """ + import pytest + + def test_1(): pass + + @pytest.mark.first + def test_2(): pass + """ + assert item_names_for(tests_content) == ['test_2', 'test_1'] + + +def test_second(item_names_for): + tests_content = """ + import pytest + + def test_1(): pass + def test_2(): pass + def test_3(): pass + def test_4(): pass + + @pytest.mark.second + def test_5(): pass + """ + assert item_names_for(tests_content) == ['test_1', 'test_5', 'test_2', 'test_3', 'test_4'] + + +def test_third(item_names_for): + tests_content = """ + import pytest + + def test_1(): pass + def test_2(): pass + def test_3(): pass + + @pytest.mark.third + def test_4(): pass + + def test_5(): pass + """ + assert item_names_for(tests_content) == ['test_1', 'test_2', 'test_4', 'test_3', 'test_5'] + + +def test_second_to_last(item_names_for): + tests_content = """ + import pytest + + def test_1(): pass + + @pytest.mark.second_to_last + def test_2(): pass + + def test_3(): pass + def test_4(): pass + def test_5(): pass + """ + assert item_names_for(tests_content) == ['test_1', 'test_3', 'test_4', 'test_2', 'test_5'] + + +def test_last(item_names_for): + tests_content = """ + import pytest + + @pytest.mark.last + def test_1(): pass + + def test_2(): pass + """ + assert item_names_for(tests_content) == ['test_2', 'test_1'] + + +def test_first_last(item_names_for): + tests_content = """ + import pytest + + @pytest.mark.last + def test_1(): pass + + @pytest.mark.first + def test_2(): pass + + def test_3(): pass + """ + assert item_names_for(tests_content) == ['test_2', 'test_3', 'test_1']