Skip to content

Commit

Permalink
Merge 988a723 into 4b64ff7
Browse files Browse the repository at this point in the history
  • Loading branch information
osherdp committed Jul 21, 2018
2 parents 4b64ff7 + 988a723 commit ac8efda
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/rotest/cli/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ def discover_tests_under_paths(paths):

module = py.path.local(path).pyimport()
tests_discovered = loader.loadTestsFromModule(module)
tests_discovered = [test
for test in tests_discovered
if is_test_class(test)]
tests_discovered = [
test
for test in tests_discovered
if is_test_class(test) and test.__module__ == module.__name__]

core_log.debug("Discovered %d tests in %s",
len(tests_discovered), path)
Expand Down
6 changes: 5 additions & 1 deletion src/rotest/core/flow_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ def parametrize(cls, **parameters):
"""
new_common = cls.common.copy()
new_common.update(**parameters)
return type(cls.__name__, (cls,), {'common': new_common})
return type(parameters.get("__name__") or cls.__name__,
(cls,),
dict(common=new_common,
__doc__=cls.__doc__,
__module__=cls.__module__))

# Shortcut
params = parametrize
Expand Down
21 changes: 20 additions & 1 deletion tests/cli/test_discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,37 @@ def test_skipping_files_by_blacklist():
@mock.patch("rotest.cli.discover.get_test_files",
mock.MagicMock(return_value=["some_test.py"]))
@mock.patch("unittest.TestLoader")
@mock.patch("py.path", mock.MagicMock())
@mock.patch("py.path.local.pyimport",
mock.MagicMock(return_value=mock.MagicMock(__name__="the_module")))
def test_discovering_tests(loader_mock):
class Case(TestCase):
def test(self):
pass

Case.__module__ = "the_module"
loader_mock.return_value.loadTestsFromModule.return_value = [Case]

with mock.patch("__builtin__.__import__"):
assert discover_tests_under_paths(["some_test.py"]) == {Case}


@mock.patch("rotest.cli.discover.get_test_files",
mock.MagicMock(return_value=["some_test.py"]))
@mock.patch("unittest.TestLoader")
@mock.patch("py.path.local.pyimport",
mock.MagicMock(return_value=mock.MagicMock(__name__="the_module")))
def test_not_discovering_tests_on_other_module(loader_mock):
class Case(TestCase):
def test(self):
pass

Case.__module__ = "other_module"
loader_mock.return_value.loadTestsFromModule.return_value = [Case]

with mock.patch("__builtin__.__import__"):
assert discover_tests_under_paths(["some_test.py"]) == {}


def test_importing_bad_file():
with Patcher() as patcher:
patcher.fs.create_file("some_bad_test.py")
Expand Down

0 comments on commit ac8efda

Please sign in to comment.