Skip to content

Commit

Permalink
Move to py.test!
Browse files Browse the repository at this point in the history
Also enforce ordering of tests and test files, given nodeids for generators
depend upon iteration number, and pytest-expect relies on them.
  • Loading branch information
gsnedders committed Dec 3, 2015
1 parent 71ac558 commit 383d1ee
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ install:
- bash requirements-install.sh

script:
- nosetests
- py.test
- bash flake8-run.sh

after_script:
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ Please report any bugs on the `issue tracker
Tests
-----

Unit tests require the ``nose`` and ``mock`` libraries and can be run
using the ``nosetests`` command in the root directory; ``ordereddict``
is required under Python 2.6. All should pass.
Unit tests require the ``pytest`` and ``mock`` libraries and can be
run using the ``py.test`` command in the root directory;
``ordereddict`` is required under Python 2.6. All should pass.

Test data are contained in a separate `html5lib-tests
<https://github.com/html5lib/html5lib-tests>`_ repository and included
Expand Down
2 changes: 1 addition & 1 deletion html5lib/tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@


def get_data_files(subdirectory, files='*.dat'):
return glob.glob(os.path.join(test_dir, subdirectory, files))
return sorted(glob.glob(os.path.join(test_dir, subdirectory, files)))


class DefaultDict(dict):
Expand Down
2 changes: 1 addition & 1 deletion html5lib/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_parser():
if errors:
errors = errors.split("\n")

for treeName, treeCls in treeTypes.items():
for treeName, treeCls in sorted(treeTypes.items()):
for namespaceHTMLElements in (True, False):
yield (runParserTest, innerHTML, input, expected, errors, treeCls,
namespaceHTMLElements)
6 changes: 3 additions & 3 deletions html5lib/tests/test_treewalkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_all_tokens(self):
{'data': {}, 'type': 'EndTag', 'namespace': 'http:https://www.w3.org/1999/xhtml', 'name': 'body'},
{'data': {}, 'type': 'EndTag', 'namespace': 'http:https://www.w3.org/1999/xhtml', 'name': 'html'}
]
for treeName, treeCls in treeTypes.items():
for treeName, treeCls in sorted(treeTypes.items()):
p = html5parser.HTMLParser(tree=treeCls["builder"])
document = p.parse("<html><head></head><body>a<div>b</div>c</body></html>")
document = treeCls.get("adapter", lambda x: x)(document)
Expand Down Expand Up @@ -130,7 +130,7 @@ def runTreewalkerTest(innerHTML, input, expected, errors, treeClass):
def test_treewalker():
sys.stdout.write('Testing tree walkers ' + " ".join(list(treeTypes.keys())) + "\n")

for treeName, treeCls in treeTypes.items():
for treeName, treeCls in sorted(treeTypes.items()):
files = get_data_files('tree-construction')
for filename in files:
testName = os.path.basename(filename).replace(".dat", "")
Expand Down Expand Up @@ -194,6 +194,6 @@ def test_treewalker_six_mix():
'<link>\n href="http:https://example.com/cow"\n rel="alternate"\n "Example"')
]

for tree in treeTypes.items():
for tree in sorted(treeTypes.items()):
for intext, attrs, expected in sm_tests:
yield runTreewalkerEditTest, intext, expected, attrs, tree
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = -rXw -p no:doctest
3 changes: 2 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-r requirements.txt

flake8
nose
pytest
pytest-expect>=1.0,<2.0
mock
ordereddict ; python_version < '2.7'
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ envlist = {py26,py27,py32,py33,py34,py35,pypy,pypy3}-{base,optional}
[testenv]
deps =
flake8
nose
pytest
pytest-expect>=1.0,<2.0
mock
py26-base: ordereddict
optional: -r{toxinidir}/requirements-optional.txt

commands =
{envbindir}/nosetests -q
{envbindir}/py.test
{toxinidir}/flake8-run.sh

0 comments on commit 383d1ee

Please sign in to comment.