Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests for ordinal behavior (#14) #29

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ lib
lib64
__pycache__

# PyCharm
.idea

# Virtualenvs
env

Expand Down
46 changes: 23 additions & 23 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
19 changes: 19 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import re

import pytest
import pytest_ordering


Expand All @@ -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
68 changes: 0 additions & 68 deletions tests/test_ordering.py
Original file line number Diff line number Diff line change
@@ -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 = """
Expand All @@ -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
Expand Down Expand Up @@ -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
87 changes: 87 additions & 0 deletions tests/test_ordinals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's this test file that has the new tests.


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']