Skip to content

Commit

Permalink
REMOVE-DEPENDENCY: nose (to avoid nose.importer warnings)
Browse files Browse the repository at this point in the history
Replace nose test-framework functionality w/ pytest.
Move test/*.py => tests/unit/*.py
  • Loading branch information
jenisys committed Jul 6, 2019
1 parent 1789492 commit d086029
Show file tree
Hide file tree
Showing 30 changed files with 283 additions and 369 deletions.
2 changes: 0 additions & 2 deletions MANIFEST.in
Expand Up @@ -33,5 +33,3 @@ recursive-include py.requirements *.txt

prune .tox
prune .venv*
prune paver_ext
exclude pavement.py
13 changes: 13 additions & 0 deletions conftest.py
Expand Up @@ -10,6 +10,10 @@
import behave
import pytest


# ---------------------------------------------------------------------------
# PYTEST FIXTURES:
# ---------------------------------------------------------------------------
@pytest.fixture(autouse=True)
def _annotate_environment(request):
"""Add project-specific information to test-run environment:
Expand All @@ -25,3 +29,12 @@ def _annotate_environment(request):
behave_version = behave.__version__
environment.append(("behave", behave_version))

_pytest_version = pytest.__version__
if _pytest_version >= "5.0":
# -- SUPPORTED SINCE: pytest 5.0
@pytest.fixture(scope="session", autouse=True)
def log_global_env_facts(record_testsuite_property):
# SEE: https://docs.pytest.org/en/latest/usage.html
behave_version = behave.__version__
record_testsuite_property("BEHAVE_VERSION", behave_version)

1 change: 1 addition & 0 deletions invoke.yaml
Expand Up @@ -23,6 +23,7 @@ sphinx:
languages:
- de
# PREPARED: - zh-CN

cleanup:
extra_directories:
- "build"
Expand Down
9 changes: 9 additions & 0 deletions py.requirements/ci.tox.txt
@@ -0,0 +1,9 @@
# ============================================================================
# BEHAVE: PYTHON PACKAGE REQUIREMENTS: ci.tox.txt
# ============================================================================

pytest >= 4.2
pytest-html >= 1.19.0
mock >= 2.0
PyHamcrest >= 1.9
path.py >= 10.1
1 change: 0 additions & 1 deletion py.requirements/ci.travis.txt
@@ -1,5 +1,4 @@
mock
nose
PyHamcrest >= 1.9
pytest >= 3.0
pytest-html >= 1.19.0
Expand Down
1 change: 0 additions & 1 deletion py.requirements/develop.txt
Expand Up @@ -14,7 +14,6 @@ pycmd
bumpversion >= 0.4.0

# -- DEVELOPMENT SUPPORT:
# PREPARED: nose-cov >= 1.4
tox >= 1.8.1
coverage >= 4.2
pytest-cov
Expand Down
3 changes: 1 addition & 2 deletions py.requirements/testing.txt
Expand Up @@ -4,9 +4,8 @@

# -- TESTING: Unit tests and behave self-tests.
# PREPARED-FUTURE: behave4cmd0, behave4cmd
pytest >= 3.0
pytest >= 4.2
pytest-html >= 1.19.0
nose >= 1.3
mock >= 2.0
PyHamcrest >= 1.9

Expand Down
7 changes: 4 additions & 3 deletions pytest.ini
Expand Up @@ -16,8 +16,8 @@
# ============================================================================

[pytest]
minversion = 2.8
testpaths = test tests
minversion = 4.2
testpaths = tests
python_files = test_*.py
addopts = --metadata PACKAGE_UNDER_TEST behave
--metadata PACKAGE_VERSION 1.2.7.dev1
Expand All @@ -26,6 +26,7 @@ addopts = --metadata PACKAGE_UNDER_TEST behave
markers =
smoke
slow

# -- BACKWARD COMPATIBILITY: pytest < 2.8
norecursedirs = .git .tox build dist py.requirements tmp* _WORKSPACE
# norecursedirs = .git .tox build dist py.requirements tmp* _WORKSPACE

8 changes: 3 additions & 5 deletions setup.py
Expand Up @@ -86,13 +86,11 @@ def find_packages_by_root_package(where):
"win_unicode_console; python_version < '3.6'",
"colorama",
],
test_suite="nose.collector",
tests_require=[
"pytest >= 3.0",
"pytest >= 4.2",
"pytest-html >= 1.19.0",
"nose >= 1.3",
"mock >= 1.1",
"PyHamcrest >= 1.8",
"PyHamcrest >= 1.9",
"path.py >= 11.5.0"
],
cmdclass = {
Expand All @@ -105,7 +103,7 @@ def find_packages_by_root_package(where):
],
"develop": [
"coverage",
"pytest >= 3.0",
"pytest >= 4.2",
"pytest-html >= 1.19.0",
"pytest-cov",
"tox",
Expand Down
2 changes: 1 addition & 1 deletion tasks/test.py
Expand Up @@ -172,7 +172,7 @@ def grouped_by_prefix(args, prefixes):
},
},
"pytest": {
"scopes": ["test", "tests"],
"scopes": ["tests"],
"args": "",
"options": "", # -- NOTE: Overide in configfile "invoke.yaml"
},
Expand Down
Empty file removed test/__init__.py
Empty file.
151 changes: 0 additions & 151 deletions test/test_importer.py

This file was deleted.

File renamed without changes.
2 changes: 0 additions & 2 deletions tests/unit/reporter/test_summary.py
Expand Up @@ -4,8 +4,6 @@
import sys
import pytest
from mock import Mock, patch
# NOT-NEEDED: from nose.tools import *

from behave.model import ScenarioOutline, Scenario
from behave.model_core import Status
from behave.reporter.summary import SummaryReporter, format_summary
Expand Down
17 changes: 10 additions & 7 deletions tests/unit/tag_expression/test_tag_expression_v1_part1.py
Expand Up @@ -2,7 +2,7 @@

from __future__ import absolute_import
from behave.tag_expression import TagExpression
from nose import tools
import pytest
import unittest


Expand Down Expand Up @@ -476,31 +476,34 @@ def setUp(self):
self.e = TagExpression(['foo:3,-bar', 'zap:5'])

def test_should_count_tags_for_positive_tags(self):
tools.eq_(self.e.limits, {'foo': 3, 'zap': 5})
assert self.e.limits == {'foo': 3, 'zap': 5}

def test_should_match_foo_zap(self):
assert self.e.check(['foo', 'zap'])


class TestTagExpressionParsing(unittest.TestCase):
def setUp(self):
self.e = TagExpression([' foo:3 , -bar ', ' zap:5 '])

def test_should_have_limits(self):
tools.eq_(self.e.limits, {'zap': 5, 'foo': 3})
assert self.e.limits == {'zap': 5, 'foo': 3}


class TestTagExpressionTagLimits(unittest.TestCase):
def test_should_be_counted_for_negative_tags(self):
e = TagExpression(['-todo:3'])
tools.eq_(e.limits, {'todo': 3})
assert e.limits == {'todo': 3}

def test_should_be_counted_for_positive_tags(self):
e = TagExpression(['todo:3'])
tools.eq_(e.limits, {'todo': 3})
assert e.limits == {'todo': 3}

def test_should_raise_an_error_for_inconsistent_limits(self):
tools.assert_raises(Exception, TagExpression, ['todo:3', '-todo:4'])
with pytest.raises(Exception):
_ = TagExpression(['todo:3', '-todo:4'])

def test_should_allow_duplicate_consistent_limits(self):
e = TagExpression(['todo:3', '-todo:3'])
tools.eq_(e.limits, {'todo': 3})
assert e.limits == {'todo': 3}

18 changes: 10 additions & 8 deletions tests/unit/tag_expression/test_tag_expression_v1_part2.py
Expand Up @@ -6,10 +6,11 @@
"""

from __future__ import absolute_import
from behave.tag_expression import TagExpression
from nose import tools
import itertools
from six.moves import range
import pytest
from behave.tag_expression import TagExpression


has_combinations = hasattr(itertools, "combinations")
if has_combinations:
Expand All @@ -31,6 +32,7 @@ def make_tags_line(tags):
return "@" + " @".join(tags)
return NO_TAGS


TestCase = object
# ----------------------------------------------------------------------------
# TEST: all_combinations() test helper
Expand All @@ -45,8 +47,8 @@ def test_all_combinations_with_2values(self):
('@one', '@two'),
]
actual = all_combinations(items)
tools.eq_(actual, expected)
tools.eq_(len(actual), 4)
assert actual == expected
assert len(actual) == 4

def test_all_combinations_with_3values(self):
items = "@one @two @three".split()
Expand All @@ -61,8 +63,8 @@ def test_all_combinations_with_3values(self):
('@one', '@two', '@three'),
]
actual = all_combinations(items)
tools.eq_(actual, expected)
tools.eq_(len(actual), 8)
assert actual == expected
assert len(actual) == 8


# ----------------------------------------------------------------------------
Expand All @@ -74,13 +76,13 @@ def assert_tag_expression_matches(self, tag_expression,
tag_combinations, expected):
matched = [ make_tags_line(c) for c in tag_combinations
if tag_expression.check(c) ]
tools.eq_(matched, expected)
assert matched == expected

def assert_tag_expression_mismatches(self, tag_expression,
tag_combinations, expected):
mismatched = [ make_tags_line(c) for c in tag_combinations
if not tag_expression.check(c) ]
tools.eq_(mismatched, expected)
assert mismatched == expected


class TestTagExpressionWith1Term(TagExpressionTestCase):
Expand Down

0 comments on commit d086029

Please sign in to comment.