def test_nested_suite(self): stub = Stub() discovered = StubDiscoveredTests(stub) session = StubPytestSession(stub) testroot = fix_path('/a/b/c') relfile = fix_path('x/y/z/test_eggs.py') session.items = [ StubFunctionItem( stub, nodeid=relfile + '::SpamTests::Ham::Eggs::test_spam', name='test_spam', location=(relfile, 12, 'SpamTests.Ham.Eggs.test_spam'), fspath=PATH_JOIN(testroot, relfile), function=FakeFunc('test_spam'), ), ] collector = TestCollector(tests=discovered) collector.pytest_collection_finish(session) self.maxDiff = None self.assertEqual(stub.calls, [ ('discovered.reset', None, None), ('discovered.add_test', None, dict( parents=[ ('./x/y/z/test_eggs.py::SpamTests::Ham::Eggs', 'Eggs', 'suite'), ('./x/y/z/test_eggs.py::SpamTests::Ham', 'Ham', 'suite'), ('./x/y/z/test_eggs.py::SpamTests', 'SpamTests', 'suite'), ('./x/y/z/test_eggs.py', 'test_eggs.py', 'file'), ('./x/y/z', 'z', 'folder'), ('./x/y', 'y', 'folder'), ('./x', 'x', 'folder'), ('.', testroot, 'folder'), ], test=TestInfo( id='./x/y/z/test_eggs.py::SpamTests::Ham::Eggs::test_spam', name='test_spam', path=TestPath( root=testroot, relfile=fix_relpath(relfile), func='SpamTests.Ham.Eggs.test_spam', sub=None, ), source='{}:{}'.format(fix_relpath(relfile), 13), markers=None, parentid='./x/y/z/test_eggs.py::SpamTests::Ham::Eggs', ), )), ])
def test_fix_relpath(self): tests = [ ('spam.py', posixpath, './spam.py'), ('eggs/spam.py', posixpath, './eggs/spam.py'), ('eggs/spam/', posixpath, './eggs/spam/'), (r'\spam.py', posixpath, r'./\spam.py'), ('spam.py', ntpath, r'.\spam.py'), (r'eggs\spam.py', ntpath, '.\eggs\spam.py'), ('eggs\\spam\\', ntpath, '.\\eggs\\spam\\'), ('/spam.py', ntpath, r'\spam.py'), # Note the fixed "/". # absolute ('/', posixpath, '/'), ('/spam.py', posixpath, '/spam.py'), ('\\', ntpath, '\\'), (r'\spam.py', ntpath, r'\spam.py'), (r'C:\spam.py', ntpath, r'C:\spam.py'), # no-op ('./spam.py', posixpath, './spam.py'), (r'.\spam.py', ntpath, r'.\spam.py'), ] # no-op for path in ['.', '..']: tests.extend([ (path, posixpath, path), (path, ntpath, path), ]) for path, _os_path, expected in tests: with self.subTest((path, _os_path.sep)): fixed = fix_relpath( path, _fix_path=(lambda p: fix_path(p, _pathsep=_os_path.sep)), _path_isabs=_os_path.isabs, _pathsep=_os_path.sep, ) self.assertEqual(fixed, expected)
def test_fix_relpath(self): tests = [ ("spam.py", posixpath, "./spam.py"), ("eggs/spam.py", posixpath, "./eggs/spam.py"), ("eggs/spam/", posixpath, "./eggs/spam/"), (r"\spam.py", posixpath, r"./\spam.py"), ("spam.py", ntpath, r".\spam.py"), (r"eggs\spam.py", ntpath, ".\eggs\spam.py"), ("eggs\\spam\\", ntpath, ".\\eggs\\spam\\"), ("/spam.py", ntpath, r"\spam.py"), # Note the fixed "/". # absolute ("/", posixpath, "/"), ("/spam.py", posixpath, "/spam.py"), ("\\", ntpath, "\\"), (r"\spam.py", ntpath, r"\spam.py"), (r"C:\spam.py", ntpath, r"C:\spam.py"), # no-op ("./spam.py", posixpath, "./spam.py"), (r".\spam.py", ntpath, r".\spam.py"), ] # no-op for path in [".", ".."]: tests.extend( [(path, posixpath, path), (path, ntpath, path),] ) for path, _os_path, expected in tests: with self.subTest((path, _os_path.sep)): fixed = fix_relpath( path, _fix_path=(lambda p: fix_path(p, _pathsep=_os_path.sep)), _path_isabs=_os_path.isabs, _pathsep=_os_path.sep, ) self.assertEqual(fixed, expected)
def test_reset(self): testroot = fix_path("/a/b/c") discovered = DiscoveredTests() discovered.add_test( SingleTestInfo( id="./test_spam.py::test_each", name="test_each", path=SingleTestPath( root=testroot, relfile="test_spam.py", func="test_each", ), source="test_spam.py:11", markers=[], parentid="./test_spam.py", ), [ ("./test_spam.py", "test_spam.py", "file"), (".", testroot, "folder"), ], ) before = len(discovered), len(discovered.parents) discovered.reset() after = len(discovered), len(discovered.parents) self.assertEqual(before, (1, 2)) self.assertEqual(after, (0, 0))
def test_reset(self): testroot = fix_path('/a/b/c') discovered = DiscoveredTests() discovered.add_test( TestInfo( id='./test_spam.py::test_each', name='test_each', path=TestPath( root=testroot, relfile='test_spam.py', func='test_each', ), source='test_spam.py:11', markers=[], parentid='./test_spam.py', ), [ ('./test_spam.py', 'test_spam.py', 'file'), ('.', testroot, 'folder'), ]) before = len(discovered), len(discovered.parents) discovered.reset() after = len(discovered), len(discovered.parents) self.assertEqual(before, (1, 2)) self.assertEqual(after, (0, 0))
def test_fix_path(self): tests = [ ("./spam.py", r".\spam.py"), ("./some-dir", r".\some-dir"), ("./some-dir/", ".\\some-dir\\"), ("./some-dir/eggs", r".\some-dir\eggs"), ("./some-dir/eggs/spam.py", r".\some-dir\eggs\spam.py"), ("X/y/Z/a.B.c.PY", r"X\y\Z\a.B.c.PY"), ("/", "\\"), ("/spam", r"\spam"), ("C:/spam", r"C:\spam"), ] for path, expected in tests: pathsep = ntpath.sep with self.subTest(r"fixed for \: {!r}".format(path)): fixed = fix_path(path, _pathsep=pathsep) self.assertEqual(fixed, expected) pathsep = posixpath.sep with self.subTest("unchanged for /: {!r}".format(path)): unchanged = fix_path(path, _pathsep=pathsep) self.assertEqual(unchanged, path) # no path -> "." for path in ["", None]: for pathsep in [ntpath.sep, posixpath.sep]: with self.subTest(r"fixed for {}: {!r}".format(pathsep, path)): fixed = fix_path(path, _pathsep=pathsep) self.assertEqual(fixed, ".") # no-op paths paths = [path for _, path in tests] paths.extend( [ ".", "..", "some-dir", "spam.py", ] ) for path in paths: for pathsep in [ntpath.sep, posixpath.sep]: with self.subTest(r"unchanged for {}: {!r}".format(pathsep, path)): unchanged = fix_path(path, _pathsep=pathsep) self.assertEqual(unchanged, path)
def test_fix_path(self): tests = [ ('./spam.py', r'.\spam.py'), ('./some-dir', r'.\some-dir'), ('./some-dir/', '.\\some-dir\\'), ('./some-dir/eggs', r'.\some-dir\eggs'), ('./some-dir/eggs/spam.py', r'.\some-dir\eggs\spam.py'), ('X/y/Z/a.B.c.PY', r'X\y\Z\a.B.c.PY'), ('/', '\\'), ('/spam', r'\spam'), ('C:/spam', r'C:\spam'), ] for path, expected in tests: pathsep = ntpath.sep with self.subTest(r'fixed for \: {!r}'.format(path)): fixed = fix_path(path, _pathsep=pathsep) self.assertEqual(fixed, expected) pathsep = posixpath.sep with self.subTest('unchanged for /: {!r}'.format(path)): unchanged = fix_path(path, _pathsep=pathsep) self.assertEqual(unchanged, path) # no path -> "." for path in ['', None]: for pathsep in [ntpath.sep, posixpath.sep]: with self.subTest(r'fixed for {}: {!r}'.format(pathsep, path)): fixed = fix_path(path, _pathsep=pathsep) self.assertEqual(fixed, '.') # no-op paths paths = [path for _, path in tests] paths.extend([ '.', '..', 'some-dir', 'spam.py', ]) for path in paths: for pathsep in [ntpath.sep, posixpath.sep]: with self.subTest(r'unchanged for {}: {!r}'.format( pathsep, path)): unchanged = fix_path(path, _pathsep=pathsep) self.assertEqual(unchanged, path)
def test_add_test_simple(self): testroot = fix_path("/a/b/c") relfile = "test_spam.py" test = SingleTestInfo( # missing "./": id=relfile + "::test_spam", name="test_spam", path=SingleTestPath( root=testroot, # missing "./": relfile=relfile, func="test_spam", ), # missing "./": source="{}:{}".format(relfile, 11), markers=[], # missing "./": parentid=relfile, ) expected = test._replace(id=_fix_nodeid(test.id), parentid=_fix_nodeid(test.parentid)) discovered = DiscoveredTests() before = list(discovered), discovered.parents discovered.add_test( test, [ (relfile, relfile, "file"), (".", testroot, "folder"), ], ) after = list(discovered), discovered.parents self.maxDiff = None self.assertEqual(before, ([], [])) self.assertEqual( after, ( [expected], [ ParentInfo( id=".", kind="folder", name=testroot, ), ParentInfo( id="./test_spam.py", kind="file", name=relfile, root=testroot, relpath=relfile, parentid=".", ), ], ), )
def test_simple_basic(self): stub = StubSender() testroot = fix_path("/a/b/c") relfile = fix_path("x/y/z/test_spam.py") tests = [ TestInfo( id="test#1", name="test_spam_1", path=TestPath( root=testroot, relfile=relfile, func="MySuite.test_spam_1", sub=None, ), source="{}:{}".format(relfile, 10), markers=None, parentid="suite#1", ), ] parents = None expected = [{ "id": "test#1", "name": "test_spam_1", "testroot": testroot, "relfile": relfile, "lineno": 10, "testfunc": "MySuite.test_spam_1", "subtest": None, "markers": [], }] report_discovered(tests, parents, simple=True, _send=stub.send) self.maxDiff = None self.assertEqual( stub.calls, [ ("send", (expected, ), None), ], )
def test_simple_basic(self): stub = StubSender() testroot = fix_path('/a/b/c') relfile = fix_path('x/y/z/test_spam.py') tests = [ TestInfo( id='test#1', name='test_spam_1', path=TestPath( root=testroot, relfile=relfile, func='MySuite.test_spam_1', sub=None, ), source='{}:{}'.format(relfile, 10), markers=None, parentid='suite#1', ), ] parents = None expected = [{ 'id': 'test#1', 'name': 'test_spam_1', 'testroot': testroot, 'relfile': relfile, 'lineno': 10, 'testfunc': 'MySuite.test_spam_1', 'subtest': None, 'markers': [], }] report_discovered(tests, parents, simple=True, _send=stub.send) self.maxDiff = None self.assertEqual(stub.calls, [ ('send', (expected, ), None), ])
def test_add_test_simple(self): testroot = fix_path('/a/b/c') relfile = 'test_spam.py' test = TestInfo( # missing "./": id=relfile + '::test_spam', name='test_spam', path=TestPath( root=testroot, # missing "./": relfile=relfile, func='test_spam', ), # missing "./": source='{}:{}'.format(relfile, 11), markers=[], # missing "./": parentid=relfile, ) expected = test._replace(id=_fix_nodeid(test.id), parentid=_fix_nodeid(test.parentid)) discovered = DiscoveredTests() before = list(discovered), discovered.parents discovered.add_test(test, [ (relfile, relfile, 'file'), ('.', testroot, 'folder'), ]) after = list(discovered), discovered.parents self.maxDiff = None self.assertEqual(before, ([], [])) self.assertEqual(after, ([expected], [ ParentInfo( id='.', kind='folder', name=testroot, ), ParentInfo( id='./test_spam.py', kind='file', name=relfile, root=testroot, relpath=relfile, parentid='.', ), ]))
def test_parents(self): testroot = fix_path('/a/b/c') relfile = fix_path('x/y/z/test_spam.py') tests = [ TestInfo( # missing "./", using pathsep: id=relfile + '::test_each[10-10]', name='test_each[10-10]', path=TestPath( root=testroot, relfile=fix_relpath(relfile), func='test_each', sub=['[10-10]'], ), source='{}:{}'.format(relfile, 10), markers=None, # missing "./", using pathsep: parentid=relfile + '::test_each', ), TestInfo( # missing "./", using pathsep: id=relfile + '::All::BasicTests::test_first', name='test_first', path=TestPath( root=testroot, relfile=fix_relpath(relfile), func='All.BasicTests.test_first', sub=None, ), source='{}:{}'.format(relfile, 61), markers=None, # missing "./", using pathsep: parentid=relfile + '::All::BasicTests', ), ] allparents = [ # missing "./", using pathsep: [ (relfile + '::test_each', 'test_each', 'function'), (relfile, relfile, 'file'), ('.', testroot, 'folder'), ], # missing "./", using pathsep: [ (relfile + '::All::BasicTests', 'BasicTests', 'suite'), (relfile + '::All', 'All', 'suite'), (relfile, 'test_spam.py', 'file'), (fix_path('x/y/z'), 'z', 'folder'), (fix_path('x/y'), 'y', 'folder'), (fix_path('./x'), 'x', 'folder'), ('.', testroot, 'folder'), ], ] discovered = DiscoveredTests() for test, parents in zip(tests, allparents): discovered.add_test(test, parents) parents = discovered.parents self.maxDiff = None self.assertEqual(parents, [ ParentInfo( id='.', kind='folder', name=testroot, ), ParentInfo( id='./x', kind='folder', name='x', root=testroot, relpath=fix_path('./x'), parentid='.', ), ParentInfo( id='./x/y', kind='folder', name='y', root=testroot, relpath=fix_path('./x/y'), parentid='./x', ), ParentInfo( id='./x/y/z', kind='folder', name='z', root=testroot, relpath=fix_path('./x/y/z'), parentid='./x/y', ), ParentInfo( id='./x/y/z/test_spam.py', kind='file', name='test_spam.py', root=testroot, relpath=fix_relpath(relfile), parentid='./x/y/z', ), ParentInfo( id='./x/y/z/test_spam.py::All', kind='suite', name='All', root=testroot, parentid='./x/y/z/test_spam.py', ), ParentInfo( id='./x/y/z/test_spam.py::All::BasicTests', kind='suite', name='BasicTests', root=testroot, parentid='./x/y/z/test_spam.py::All', ), ParentInfo( id='./x/y/z/test_spam.py::test_each', kind='function', name='test_each', root=testroot, parentid='./x/y/z/test_spam.py', ), ])
def test_parents(self): testroot = fix_path("/a/b/c") relfile = fix_path("x/y/z/test_spam.py") tests = [ SingleTestInfo( # missing "./", using pathsep: id=relfile + "::test_each[10-10]", name="test_each[10-10]", path=SingleTestPath( root=testroot, relfile=fix_relpath(relfile), func="test_each", sub=["[10-10]"], ), source="{}:{}".format(relfile, 10), markers=None, # missing "./", using pathsep: parentid=relfile + "::test_each", ), SingleTestInfo( # missing "./", using pathsep: id=relfile + "::All::BasicTests::test_first", name="test_first", path=SingleTestPath( root=testroot, relfile=fix_relpath(relfile), func="All.BasicTests.test_first", sub=None, ), source="{}:{}".format(relfile, 61), markers=None, # missing "./", using pathsep: parentid=relfile + "::All::BasicTests", ), ] allparents = [ # missing "./", using pathsep: [ (relfile + "::test_each", "test_each", "function"), (relfile, relfile, "file"), (".", testroot, "folder"), ], # missing "./", using pathsep: [ (relfile + "::All::BasicTests", "BasicTests", "suite"), (relfile + "::All", "All", "suite"), (relfile, "test_spam.py", "file"), (fix_path("x/y/z"), "z", "folder"), (fix_path("x/y"), "y", "folder"), (fix_path("./x"), "x", "folder"), (".", testroot, "folder"), ], ] discovered = DiscoveredTests() for test, parents in zip(tests, allparents): discovered.add_test(test, parents) parents = discovered.parents self.maxDiff = None self.assertEqual( parents, [ ParentInfo( id=".", kind="folder", name=testroot, ), ParentInfo( id="./x", kind="folder", name="x", root=testroot, relpath=fix_path("./x"), parentid=".", ), ParentInfo( id="./x/y", kind="folder", name="y", root=testroot, relpath=fix_path("./x/y"), parentid="./x", ), ParentInfo( id="./x/y/z", kind="folder", name="z", root=testroot, relpath=fix_path("./x/y/z"), parentid="./x/y", ), ParentInfo( id="./x/y/z/test_spam.py", kind="file", name="test_spam.py", root=testroot, relpath=fix_relpath(relfile), parentid="./x/y/z", ), ParentInfo( id="./x/y/z/test_spam.py::All", kind="suite", name="All", root=testroot, parentid="./x/y/z/test_spam.py", ), ParentInfo( id="./x/y/z/test_spam.py::All::BasicTests", kind="suite", name="BasicTests", root=testroot, parentid="./x/y/z/test_spam.py::All", ), ParentInfo( id="./x/y/z/test_spam.py::test_each", kind="function", name="test_each", root=testroot, parentid="./x/y/z/test_spam.py", ), ], )
def test_list(self): testroot = fix_path("/a/b/c") relfile = fix_path("./test_spam.py") tests = [ SingleTestInfo( # missing "./": id="test_spam.py::test_each[10-10]", name="test_each[10-10]", path=SingleTestPath( root=testroot, relfile=relfile, func="test_each", sub=["[10-10]"], ), source="{}:{}".format(relfile, 10), markers=None, # missing "./": parentid="test_spam.py::test_each", ), SingleTestInfo( id="test_spam.py::All::BasicTests::test_first", name="test_first", path=SingleTestPath( root=testroot, relfile=relfile, func="All.BasicTests.test_first", sub=None, ), source="{}:{}".format(relfile, 62), markers=None, parentid="test_spam.py::All::BasicTests", ), ] allparents = [ [ (fix_path("./test_spam.py::test_each"), "test_each", "function"), (fix_path("./test_spam.py"), "test_spam.py", "file"), (".", testroot, "folder"), ], [ (fix_path("./test_spam.py::All::BasicTests"), "BasicTests", "suite"), (fix_path("./test_spam.py::All"), "All", "suite"), (fix_path("./test_spam.py"), "test_spam.py", "file"), (".", testroot, "folder"), ], ] expected = [ test._replace(id=_fix_nodeid(test.id), parentid=_fix_nodeid(test.parentid)) for test in tests ] discovered = DiscoveredTests() for test, parents in zip(tests, allparents): discovered.add_test(test, parents) size = len(discovered) items = [discovered[0], discovered[1]] snapshot = list(discovered) self.maxDiff = None self.assertEqual(size, 2) self.assertEqual(items, expected) self.assertEqual(snapshot, expected)
def test_multiroot(self): stub = StubSender() # the first root testroot1 = fix_path("/a/b/c") relfileid1 = "./test_spam.py" relpath1 = fix_path(relfileid1) relfile1 = relpath1[2:] tests = [ TestInfo( id=relfileid1 + "::test_spam", name="test_spam", path=TestPath( root=testroot1, relfile=relfile1, func="test_spam", ), source="{}:{}".format(relfile1, 10), markers=[], parentid=relfileid1, ), ] parents = [ ParentInfo( id=".", kind="folder", name=testroot1, ), ParentInfo( id=relfileid1, kind="file", name="test_spam.py", root=testroot1, relpath=relpath1, parentid=".", ), ] expected = [ { "rootid": ".", "root": testroot1, "parents": [ { "id": relfileid1, "kind": "file", "name": "test_spam.py", "relpath": relpath1, "parentid": ".", }, ], "tests": [{ "id": relfileid1 + "::test_spam", "name": "test_spam", "source": "{}:{}".format(relfile1, 10), "markers": [], "parentid": relfileid1, }], }, ] # the second root testroot2 = fix_path("/x/y/z") relfileid2 = "./w/test_eggs.py" relpath2 = fix_path(relfileid2) relfile2 = relpath2[2:] tests.extend([ TestInfo( id=relfileid2 + "::BasicTests::test_first", name="test_first", path=TestPath( root=testroot2, relfile=relfile2, func="BasicTests.test_first", ), source="{}:{}".format(relfile2, 61), markers=[], parentid=relfileid2 + "::BasicTests", ), ]) parents.extend([ ParentInfo( id=".", kind="folder", name=testroot2, ), ParentInfo( id="./w", kind="folder", name="w", root=testroot2, relpath=fix_path("./w"), parentid=".", ), ParentInfo( id=relfileid2, kind="file", name="test_eggs.py", root=testroot2, relpath=relpath2, parentid="./w", ), ParentInfo( id=relfileid2 + "::BasicTests", kind="suite", name="BasicTests", root=testroot2, parentid=relfileid2, ), ]) expected.extend([ { "rootid": ".", "root": testroot2, "parents": [ { "id": "./w", "kind": "folder", "name": "w", "relpath": fix_path("./w"), "parentid": ".", }, { "id": relfileid2, "kind": "file", "name": "test_eggs.py", "relpath": relpath2, "parentid": "./w", }, { "id": relfileid2 + "::BasicTests", "kind": "suite", "name": "BasicTests", "parentid": relfileid2, }, ], "tests": [{ "id": relfileid2 + "::BasicTests::test_first", "name": "test_first", "source": "{}:{}".format(relfile2, 61), "markers": [], "parentid": relfileid2 + "::BasicTests", }], }, ]) report_discovered(tests, parents, _send=stub.send) self.maxDiff = None self.assertEqual(stub.calls, [ ("send", (expected, ), None), ])
def test_doctest(self): testroot = fix_path("/a/b/c") doctestfile = fix_path("./x/test_doctest.txt") relfile = fix_path("./x/y/z/test_eggs.py") alltests = [ SingleTestInfo( id=doctestfile + "::test_doctest.txt", name="test_doctest.txt", path=SingleTestPath( root=testroot, relfile=doctestfile, func=None, ), source="{}:{}".format(doctestfile, 0), markers=[], parentid=doctestfile, ), # With --doctest-modules SingleTestInfo( id=relfile + "::test_eggs", name="test_eggs", path=SingleTestPath( root=testroot, relfile=relfile, func=None, ), source="{}:{}".format(relfile, 0), markers=[], parentid=relfile, ), SingleTestInfo( id=relfile + "::test_eggs.TestSpam", name="test_eggs.TestSpam", path=SingleTestPath( root=testroot, relfile=relfile, func=None, ), source="{}:{}".format(relfile, 12), markers=[], parentid=relfile, ), SingleTestInfo( id=relfile + "::test_eggs.TestSpam.TestEggs", name="test_eggs.TestSpam.TestEggs", path=SingleTestPath( root=testroot, relfile=relfile, func=None, ), source="{}:{}".format(relfile, 27), markers=[], parentid=relfile, ), ] allparents = [ [ (doctestfile, "test_doctest.txt", "file"), (fix_path("./x"), "x", "folder"), (".", testroot, "folder"), ], [ (relfile, "test_eggs.py", "file"), (fix_path("./x/y/z"), "z", "folder"), (fix_path("./x/y"), "y", "folder"), (fix_path("./x"), "x", "folder"), (".", testroot, "folder"), ], [ (relfile, "test_eggs.py", "file"), (fix_path("./x/y/z"), "z", "folder"), (fix_path("./x/y"), "y", "folder"), (fix_path("./x"), "x", "folder"), (".", testroot, "folder"), ], [ (relfile, "test_eggs.py", "file"), (fix_path("./x/y/z"), "z", "folder"), (fix_path("./x/y"), "y", "folder"), (fix_path("./x"), "x", "folder"), (".", testroot, "folder"), ], ] expected = [ test._replace(id=_fix_nodeid(test.id), parentid=_fix_nodeid(test.parentid)) for test in alltests ] discovered = DiscoveredTests() for test, parents in zip(alltests, allparents): discovered.add_test(test, parents) tests = list(discovered) parents = discovered.parents self.maxDiff = None self.assertEqual(tests, expected) self.assertEqual( parents, [ ParentInfo( id=".", kind="folder", name=testroot, ), ParentInfo( id="./x", kind="folder", name="x", root=testroot, relpath=fix_path("./x"), parentid=".", ), ParentInfo( id="./x/test_doctest.txt", kind="file", name="test_doctest.txt", root=testroot, relpath=fix_path(doctestfile), parentid="./x", ), ParentInfo( id="./x/y", kind="folder", name="y", root=testroot, relpath=fix_path("./x/y"), parentid="./x", ), ParentInfo( id="./x/y/z", kind="folder", name="z", root=testroot, relpath=fix_path("./x/y/z"), parentid="./x/y", ), ParentInfo( id="./x/y/z/test_eggs.py", kind="file", name="test_eggs.py", root=testroot, relpath=fix_relpath(relfile), parentid="./x/y/z", ), ], )
def test_nested_suite_simple(self): testroot = fix_path('/a/b/c') relfile = fix_path('./test_eggs.py') alltests = [ TestInfo( id=relfile + '::TestOuter::TestInner::test_spam', name='test_spam', path=TestPath( root=testroot, relfile=relfile, func='TestOuter.TestInner.test_spam', ), source='{}:{}'.format(relfile, 10), markers=None, parentid=relfile + '::TestOuter::TestInner', ), TestInfo( id=relfile + '::TestOuter::TestInner::test_eggs', name='test_eggs', path=TestPath( root=testroot, relfile=relfile, func='TestOuter.TestInner.test_eggs', ), source='{}:{}'.format(relfile, 21), markers=None, parentid=relfile + '::TestOuter::TestInner', ), ] allparents = [ [ (relfile + '::TestOuter::TestInner', 'TestInner', 'suite'), (relfile + '::TestOuter', 'TestOuter', 'suite'), (relfile, 'test_eggs.py', 'file'), ('.', testroot, 'folder'), ], [ (relfile + '::TestOuter::TestInner', 'TestInner', 'suite'), (relfile + '::TestOuter', 'TestOuter', 'suite'), (relfile, 'test_eggs.py', 'file'), ('.', testroot, 'folder'), ], ] expected = [ test._replace(id=_fix_nodeid(test.id), parentid=_fix_nodeid(test.parentid)) for test in alltests ] discovered = DiscoveredTests() for test, parents in zip(alltests, allparents): discovered.add_test(test, parents) tests = list(discovered) parents = discovered.parents self.maxDiff = None self.assertEqual(tests, expected) self.assertEqual(parents, [ ParentInfo( id='.', kind='folder', name=testroot, ), ParentInfo(id='./test_eggs.py', kind='file', name='test_eggs.py', root=testroot, relpath=fix_relpath(relfile), parentid='.'), ParentInfo( id='./test_eggs.py::TestOuter', kind='suite', name='TestOuter', root=testroot, parentid='./test_eggs.py', ), ParentInfo( id='./test_eggs.py::TestOuter::TestInner', kind='suite', name='TestInner', root=testroot, parentid='./test_eggs.py::TestOuter', ), ])
def test_multiroot(self): # the first root testroot1 = fix_path('/a/b/c') relfile1 = 'test_spam.py' alltests = [ TestInfo( # missing "./": id=relfile1 + '::test_spam', name='test_spam', path=TestPath( root=testroot1, relfile=fix_relpath(relfile1), func='test_spam', ), source='{}:{}'.format(relfile1, 10), markers=[], # missing "./": parentid=relfile1, ), ] allparents = [ # missing "./": [ (relfile1, 'test_spam.py', 'file'), ('.', testroot1, 'folder'), ], ] # the second root testroot2 = fix_path('/x/y/z') relfile2 = fix_path('w/test_eggs.py') alltests.extend([ TestInfo( id=relfile2 + '::BasicTests::test_first', name='test_first', path=TestPath( root=testroot2, relfile=fix_relpath(relfile2), func='BasicTests.test_first', ), source='{}:{}'.format(relfile2, 61), markers=[], parentid=relfile2 + '::BasicTests', ), ]) allparents.extend([ # missing "./", using pathsep: [ (relfile2 + '::BasicTests', 'BasicTests', 'suite'), (relfile2, 'test_eggs.py', 'file'), (fix_path('./w'), 'w', 'folder'), ('.', testroot2, 'folder'), ], ]) discovered = DiscoveredTests() for test, parents in zip(alltests, allparents): discovered.add_test(test, parents) tests = list(discovered) parents = discovered.parents self.maxDiff = None self.assertEqual( tests, [ # the first root TestInfo( id='./test_spam.py::test_spam', name='test_spam', path=TestPath( root=testroot1, relfile=fix_relpath(relfile1), func='test_spam', ), source='{}:{}'.format(relfile1, 10), markers=[], parentid='./test_spam.py', ), # the secondroot TestInfo( id='./w/test_eggs.py::BasicTests::test_first', name='test_first', path=TestPath( root=testroot2, relfile=fix_relpath(relfile2), func='BasicTests.test_first', ), source='{}:{}'.format(relfile2, 61), markers=[], parentid='./w/test_eggs.py::BasicTests', ), ]) self.assertEqual( parents, [ # the first root ParentInfo( id='.', kind='folder', name=testroot1, ), ParentInfo( id='./test_spam.py', kind='file', name='test_spam.py', root=testroot1, relpath=fix_relpath(relfile1), parentid='.', ), # the secondroot ParentInfo( id='.', kind='folder', name=testroot2, ), ParentInfo( id='./w', kind='folder', name='w', root=testroot2, relpath=fix_path('./w'), parentid='.', ), ParentInfo( id='./w/test_eggs.py', kind='file', name='test_eggs.py', root=testroot2, relpath=fix_relpath(relfile2), parentid='./w', ), ParentInfo( id='./w/test_eggs.py::BasicTests', kind='suite', name='BasicTests', root=testroot2, parentid='./w/test_eggs.py', ), ])
def test_multiroot(self): stub = StubSender() # the first root testroot1 = fix_path('/a/b/c') relfileid1 = './test_spam.py' relpath1 = fix_path(relfileid1) relfile1 = relpath1[2:] tests = [ TestInfo( id=relfileid1 + '::test_spam', name='test_spam', path=TestPath( root=testroot1, relfile=relfile1, func='test_spam', ), source='{}:{}'.format(relfile1, 10), markers=[], parentid=relfileid1, ), ] parents = [ ParentInfo( id='.', kind='folder', name=testroot1, ), ParentInfo( id=relfileid1, kind='file', name='test_spam.py', root=testroot1, relpath=relpath1, parentid='.', ), ] expected = [ { 'rootid': '.', 'root': testroot1, 'parents': [ { 'id': relfileid1, 'kind': 'file', 'name': 'test_spam.py', 'relpath': relpath1, 'parentid': '.', }, ], 'tests': [{ 'id': relfileid1 + '::test_spam', 'name': 'test_spam', 'source': '{}:{}'.format(relfile1, 10), 'markers': [], 'parentid': relfileid1, }], }, ] # the second root testroot2 = fix_path('/x/y/z') relfileid2 = './w/test_eggs.py' relpath2 = fix_path(relfileid2) relfile2 = relpath2[2:] tests.extend([ TestInfo( id=relfileid2 + '::BasicTests::test_first', name='test_first', path=TestPath( root=testroot2, relfile=relfile2, func='BasicTests.test_first', ), source='{}:{}'.format(relfile2, 61), markers=[], parentid=relfileid2 + '::BasicTests', ), ]) parents.extend([ ParentInfo( id='.', kind='folder', name=testroot2, ), ParentInfo( id='./w', kind='folder', name='w', root=testroot2, relpath=fix_path('./w'), parentid='.', ), ParentInfo( id=relfileid2, kind='file', name='test_eggs.py', root=testroot2, relpath=relpath2, parentid='./w', ), ParentInfo( id=relfileid2 + '::BasicTests', kind='suite', name='BasicTests', root=testroot2, parentid=relfileid2, ), ]) expected.extend([ { 'rootid': '.', 'root': testroot2, 'parents': [ { 'id': './w', 'kind': 'folder', 'name': 'w', 'relpath': fix_path('./w'), 'parentid': '.', }, { 'id': relfileid2, 'kind': 'file', 'name': 'test_eggs.py', 'relpath': relpath2, 'parentid': './w', }, { 'id': relfileid2 + '::BasicTests', 'kind': 'suite', 'name': 'BasicTests', 'parentid': relfileid2, }, ], 'tests': [{ 'id': relfileid2 + '::BasicTests::test_first', 'name': 'test_first', 'source': '{}:{}'.format(relfile2, 61), 'markers': [], 'parentid': relfileid2 + '::BasicTests', }], }, ]) report_discovered(tests, parents, _send=stub.send) self.maxDiff = None self.assertEqual(stub.calls, [ ('send', (expected, ), None), ])
def test_doctest(self): stub = Stub() discovered = StubDiscoveredTests(stub) session = StubPytestSession(stub) testroot = fix_path('/a/b/c') doctestfile = fix_path('x/test_doctest.txt') relfile = fix_path('x/y/z/test_eggs.py') session.items = [ StubDoctestItem( stub, nodeid=doctestfile + '::test_doctest.txt', name='test_doctest.txt', location=(doctestfile, 0, '[doctest] test_doctest.txt'), fspath=PATH_JOIN(testroot, doctestfile), ), # With --doctest-modules StubDoctestItem( stub, nodeid=relfile + '::test_eggs', name='test_eggs', location=(relfile, 0, '[doctest] test_eggs'), fspath=PATH_JOIN(testroot, relfile), ), StubDoctestItem( stub, nodeid=relfile + '::test_eggs.TestSpam', name='test_eggs.TestSpam', location=(relfile, 12, '[doctest] test_eggs.TestSpam'), fspath=PATH_JOIN(testroot, relfile), ), StubDoctestItem( stub, nodeid=relfile + '::test_eggs.TestSpam.TestEggs', name='test_eggs.TestSpam.TestEggs', location=(relfile, 27, '[doctest] test_eggs.TestSpam.TestEggs'), fspath=PATH_JOIN(testroot, relfile), ), ] collector = TestCollector(tests=discovered) collector.pytest_collection_finish(session) self.maxDiff = None self.assertEqual(stub.calls, [ ('discovered.reset', None, None), ('discovered.add_test', None, dict( parents=[ ('./x/test_doctest.txt', 'test_doctest.txt', 'file'), ('./x', 'x', 'folder'), ('.', testroot, 'folder'), ], test=TestInfo( id='./x/test_doctest.txt::test_doctest.txt', name='test_doctest.txt', path=TestPath( root=testroot, relfile=fix_relpath(doctestfile), func=None, ), source='{}:{}'.format(fix_relpath(doctestfile), 1), markers=[], parentid='./x/test_doctest.txt', ), )), ('discovered.add_test', None, dict( parents=[ ('./x/y/z/test_eggs.py', 'test_eggs.py', 'file'), ('./x/y/z', 'z', 'folder'), ('./x/y', 'y', 'folder'), ('./x', 'x', 'folder'), ('.', testroot, 'folder'), ], test=TestInfo( id='./x/y/z/test_eggs.py::test_eggs', name='test_eggs', path=TestPath( root=testroot, relfile=fix_relpath(relfile), func=None, ), source='{}:{}'.format(fix_relpath(relfile), 1), markers=[], parentid='./x/y/z/test_eggs.py', ), )), ('discovered.add_test', None, dict( parents=[ ('./x/y/z/test_eggs.py', 'test_eggs.py', 'file'), ('./x/y/z', 'z', 'folder'), ('./x/y', 'y', 'folder'), ('./x', 'x', 'folder'), ('.', testroot, 'folder'), ], test=TestInfo( id='./x/y/z/test_eggs.py::test_eggs.TestSpam', name='test_eggs.TestSpam', path=TestPath( root=testroot, relfile=fix_relpath(relfile), func=None, ), source='{}:{}'.format(fix_relpath(relfile), 13), markers=[], parentid='./x/y/z/test_eggs.py', ), )), ('discovered.add_test', None, dict( parents=[ ('./x/y/z/test_eggs.py', 'test_eggs.py', 'file'), ('./x/y/z', 'z', 'folder'), ('./x/y', 'y', 'folder'), ('./x', 'x', 'folder'), ('.', testroot, 'folder'), ], test=TestInfo( id='./x/y/z/test_eggs.py::test_eggs.TestSpam.TestEggs', name='test_eggs.TestSpam.TestEggs', path=TestPath( root=testroot, relfile=fix_relpath(relfile), func=None, ), source='{}:{}'.format(fix_relpath(relfile), 28), markers=[], parentid='./x/y/z/test_eggs.py', ), )), ])
def test_complex(self): """ /a/b/c/ test_ham.py MySuite test_x1 test_x2 /a/b/e/f/g/ w/ test_ham.py test_ham1 HamTests test_uh_oh test_whoa MoreHam test_yay sub1 sub2 sub3 test_eggs.py SpamTests test_okay x/ y/ a/ test_spam.py SpamTests test_okay b/ test_spam.py SpamTests test_okay test_spam.py SpamTests test_okay """ stub = StubSender() testroot = fix_path('/a/b/c') relfileid1 = './test_ham.py' relfileid2 = './test_spam.py' relfileid3 = './w/test_ham.py' relfileid4 = './w/test_eggs.py' relfileid5 = './x/y/a/test_spam.py' relfileid6 = './x/y/b/test_spam.py' tests = [ TestInfo( id=relfileid1 + '::MySuite::test_x1', name='test_x1', path=TestPath( root=testroot, relfile=fix_path(relfileid1), func='MySuite.test_x1', ), source='{}:{}'.format(fix_path(relfileid1), 10), markers=None, parentid=relfileid1 + '::MySuite', ), TestInfo( id=relfileid1 + '::MySuite::test_x2', name='test_x2', path=TestPath( root=testroot, relfile=fix_path(relfileid1), func='MySuite.test_x2', ), source='{}:{}'.format(fix_path(relfileid1), 21), markers=None, parentid=relfileid1 + '::MySuite', ), TestInfo( id=relfileid2 + '::SpamTests::test_okay', name='test_okay', path=TestPath( root=testroot, relfile=fix_path(relfileid2), func='SpamTests.test_okay', ), source='{}:{}'.format(fix_path(relfileid2), 17), markers=None, parentid=relfileid2 + '::SpamTests', ), TestInfo( id=relfileid3 + '::test_ham1', name='test_ham1', path=TestPath( root=testroot, relfile=fix_path(relfileid3), func='test_ham1', ), source='{}:{}'.format(fix_path(relfileid3), 8), markers=None, parentid=relfileid3, ), TestInfo( id=relfileid3 + '::HamTests::test_uh_oh', name='test_uh_oh', path=TestPath( root=testroot, relfile=fix_path(relfileid3), func='HamTests.test_uh_oh', ), source='{}:{}'.format(fix_path(relfileid3), 19), markers=['expected-failure'], parentid=relfileid3 + '::HamTests', ), TestInfo( id=relfileid3 + '::HamTests::test_whoa', name='test_whoa', path=TestPath( root=testroot, relfile=fix_path(relfileid3), func='HamTests.test_whoa', ), source='{}:{}'.format(fix_path(relfileid3), 35), markers=None, parentid=relfileid3 + '::HamTests', ), TestInfo( id=relfileid3 + '::MoreHam::test_yay[1-2]', name='test_yay[1-2]', path=TestPath( root=testroot, relfile=fix_path(relfileid3), func='MoreHam.test_yay', sub=['[1-2]'], ), source='{}:{}'.format(fix_path(relfileid3), 57), markers=None, parentid=relfileid3 + '::MoreHam::test_yay', ), TestInfo( id=relfileid3 + '::MoreHam::test_yay[1-2][3-4]', name='test_yay[1-2][3-4]', path=TestPath( root=testroot, relfile=fix_path(relfileid3), func='MoreHam.test_yay', sub=['[1-2]', '[3=4]'], ), source='{}:{}'.format(fix_path(relfileid3), 72), markers=None, parentid=relfileid3 + '::MoreHam::test_yay[1-2]', ), TestInfo( id=relfileid4 + '::SpamTests::test_okay', name='test_okay', path=TestPath( root=testroot, relfile=fix_path(relfileid4), func='SpamTests.test_okay', ), source='{}:{}'.format(fix_path(relfileid4), 15), markers=None, parentid=relfileid4 + '::SpamTests', ), TestInfo( id=relfileid5 + '::SpamTests::test_okay', name='test_okay', path=TestPath( root=testroot, relfile=fix_path(relfileid5), func='SpamTests.test_okay', ), source='{}:{}'.format(fix_path(relfileid5), 12), markers=None, parentid=relfileid5 + '::SpamTests', ), TestInfo( id=relfileid6 + '::SpamTests::test_okay', name='test_okay', path=TestPath( root=testroot, relfile=fix_path(relfileid6), func='SpamTests.test_okay', ), source='{}:{}'.format(fix_path(relfileid6), 27), markers=None, parentid=relfileid6 + '::SpamTests', ), ] parents = [ ParentInfo( id='.', kind='folder', name=testroot, ), ParentInfo( id=relfileid1, kind='file', name='test_ham.py', root=testroot, relpath=fix_path(relfileid1), parentid='.', ), ParentInfo( id=relfileid1 + '::MySuite', kind='suite', name='MySuite', root=testroot, parentid=relfileid1, ), ParentInfo( id=relfileid2, kind='file', name='test_spam.py', root=testroot, relpath=fix_path(relfileid2), parentid='.', ), ParentInfo( id=relfileid2 + '::SpamTests', kind='suite', name='SpamTests', root=testroot, parentid=relfileid2, ), ParentInfo( id='./w', kind='folder', name='w', root=testroot, relpath=fix_path('./w'), parentid='.', ), ParentInfo( id=relfileid3, kind='file', name='test_ham.py', root=testroot, relpath=fix_path(relfileid3), parentid='./w', ), ParentInfo( id=relfileid3 + '::HamTests', kind='suite', name='HamTests', root=testroot, parentid=relfileid3, ), ParentInfo( id=relfileid3 + '::MoreHam', kind='suite', name='MoreHam', root=testroot, parentid=relfileid3, ), ParentInfo( id=relfileid3 + '::MoreHam::test_yay', kind='function', name='test_yay', root=testroot, parentid=relfileid3 + '::MoreHam', ), ParentInfo( id=relfileid3 + '::MoreHam::test_yay[1-2]', kind='subtest', name='test_yay[1-2]', root=testroot, parentid=relfileid3 + '::MoreHam::test_yay', ), ParentInfo( id=relfileid4, kind='file', name='test_eggs.py', root=testroot, relpath=fix_path(relfileid4), parentid='./w', ), ParentInfo( id=relfileid4 + '::SpamTests', kind='suite', name='SpamTests', root=testroot, parentid=relfileid4, ), ParentInfo( id='./x', kind='folder', name='x', root=testroot, relpath=fix_path('./x'), parentid='.', ), ParentInfo( id='./x/y', kind='folder', name='y', root=testroot, relpath=fix_path('./x/y'), parentid='./x', ), ParentInfo( id='./x/y/a', kind='folder', name='a', root=testroot, relpath=fix_path('./x/y/a'), parentid='./x/y', ), ParentInfo( id=relfileid5, kind='file', name='test_spam.py', root=testroot, relpath=fix_path(relfileid5), parentid='./x/y/a', ), ParentInfo( id=relfileid5 + '::SpamTests', kind='suite', name='SpamTests', root=testroot, parentid=relfileid5, ), ParentInfo( id='./x/y/b', kind='folder', name='b', root=testroot, relpath=fix_path('./x/y/b'), parentid='./x/y', ), ParentInfo( id=relfileid6, kind='file', name='test_spam.py', root=testroot, relpath=fix_path(relfileid6), parentid='./x/y/b', ), ParentInfo( id=relfileid6 + '::SpamTests', kind='suite', name='SpamTests', root=testroot, parentid=relfileid6, ), ] expected = [{ 'rootid': '.', 'root': testroot, 'parents': [ { 'id': relfileid1, 'kind': 'file', 'name': 'test_ham.py', 'relpath': fix_path(relfileid1), 'parentid': '.', }, { 'id': relfileid1 + '::MySuite', 'kind': 'suite', 'name': 'MySuite', 'parentid': relfileid1, }, { 'id': relfileid2, 'kind': 'file', 'name': 'test_spam.py', 'relpath': fix_path(relfileid2), 'parentid': '.', }, { 'id': relfileid2 + '::SpamTests', 'kind': 'suite', 'name': 'SpamTests', 'parentid': relfileid2, }, { 'id': './w', 'kind': 'folder', 'name': 'w', 'relpath': fix_path('./w'), 'parentid': '.', }, { 'id': relfileid3, 'kind': 'file', 'name': 'test_ham.py', 'relpath': fix_path(relfileid3), 'parentid': './w', }, { 'id': relfileid3 + '::HamTests', 'kind': 'suite', 'name': 'HamTests', 'parentid': relfileid3, }, { 'id': relfileid3 + '::MoreHam', 'kind': 'suite', 'name': 'MoreHam', 'parentid': relfileid3, }, { 'id': relfileid3 + '::MoreHam::test_yay', 'kind': 'function', 'name': 'test_yay', 'parentid': relfileid3 + '::MoreHam', }, { 'id': relfileid3 + '::MoreHam::test_yay[1-2]', 'kind': 'subtest', 'name': 'test_yay[1-2]', 'parentid': relfileid3 + '::MoreHam::test_yay', }, { 'id': relfileid4, 'kind': 'file', 'name': 'test_eggs.py', 'relpath': fix_path(relfileid4), 'parentid': './w', }, { 'id': relfileid4 + '::SpamTests', 'kind': 'suite', 'name': 'SpamTests', 'parentid': relfileid4, }, { 'id': './x', 'kind': 'folder', 'name': 'x', 'relpath': fix_path('./x'), 'parentid': '.', }, { 'id': './x/y', 'kind': 'folder', 'name': 'y', 'relpath': fix_path('./x/y'), 'parentid': './x', }, { 'id': './x/y/a', 'kind': 'folder', 'name': 'a', 'relpath': fix_path('./x/y/a'), 'parentid': './x/y', }, { 'id': relfileid5, 'kind': 'file', 'name': 'test_spam.py', 'relpath': fix_path(relfileid5), 'parentid': './x/y/a', }, { 'id': relfileid5 + '::SpamTests', 'kind': 'suite', 'name': 'SpamTests', 'parentid': relfileid5, }, { 'id': './x/y/b', 'kind': 'folder', 'name': 'b', 'relpath': fix_path('./x/y/b'), 'parentid': './x/y', }, { 'id': relfileid6, 'kind': 'file', 'name': 'test_spam.py', 'relpath': fix_path(relfileid6), 'parentid': './x/y/b', }, { 'id': relfileid6 + '::SpamTests', 'kind': 'suite', 'name': 'SpamTests', 'parentid': relfileid6, }, ], 'tests': [ { 'id': relfileid1 + '::MySuite::test_x1', 'name': 'test_x1', 'source': '{}:{}'.format(fix_path(relfileid1), 10), 'markers': [], 'parentid': relfileid1 + '::MySuite', }, { 'id': relfileid1 + '::MySuite::test_x2', 'name': 'test_x2', 'source': '{}:{}'.format(fix_path(relfileid1), 21), 'markers': [], 'parentid': relfileid1 + '::MySuite', }, { 'id': relfileid2 + '::SpamTests::test_okay', 'name': 'test_okay', 'source': '{}:{}'.format(fix_path(relfileid2), 17), 'markers': [], 'parentid': relfileid2 + '::SpamTests', }, { 'id': relfileid3 + '::test_ham1', 'name': 'test_ham1', 'source': '{}:{}'.format(fix_path(relfileid3), 8), 'markers': [], 'parentid': relfileid3, }, { 'id': relfileid3 + '::HamTests::test_uh_oh', 'name': 'test_uh_oh', 'source': '{}:{}'.format(fix_path(relfileid3), 19), 'markers': ['expected-failure'], 'parentid': relfileid3 + '::HamTests', }, { 'id': relfileid3 + '::HamTests::test_whoa', 'name': 'test_whoa', 'source': '{}:{}'.format(fix_path(relfileid3), 35), 'markers': [], 'parentid': relfileid3 + '::HamTests', }, { 'id': relfileid3 + '::MoreHam::test_yay[1-2]', 'name': 'test_yay[1-2]', 'source': '{}:{}'.format(fix_path(relfileid3), 57), 'markers': [], 'parentid': relfileid3 + '::MoreHam::test_yay', }, { 'id': relfileid3 + '::MoreHam::test_yay[1-2][3-4]', 'name': 'test_yay[1-2][3-4]', 'source': '{}:{}'.format(fix_path(relfileid3), 72), 'markers': [], 'parentid': relfileid3 + '::MoreHam::test_yay[1-2]', }, { 'id': relfileid4 + '::SpamTests::test_okay', 'name': 'test_okay', 'source': '{}:{}'.format(fix_path(relfileid4), 15), 'markers': [], 'parentid': relfileid4 + '::SpamTests', }, { 'id': relfileid5 + '::SpamTests::test_okay', 'name': 'test_okay', 'source': '{}:{}'.format(fix_path(relfileid5), 12), 'markers': [], 'parentid': relfileid5 + '::SpamTests', }, { 'id': relfileid6 + '::SpamTests::test_okay', 'name': 'test_okay', 'source': '{}:{}'.format(fix_path(relfileid6), 27), 'markers': [], 'parentid': relfileid6 + '::SpamTests', }, ], }] report_discovered(tests, parents, _send=stub.send) self.maxDiff = None self.assertEqual(stub.calls, [ ('send', (expected, ), None), ])
def test_basic(self): stub = StubSender() testroot = fix_path('/a/b/c') relfile = 'test_spam.py' relpath = fix_relpath(relfile) tests = [ TestInfo( id='test#1', name='test_spam', path=TestPath( root=testroot, relfile=relfile, func='test_spam', ), source='{}:{}'.format(relfile, 10), markers=[], parentid='file#1', ), ] parents = [ ParentInfo( id='<root>', kind='folder', name=testroot, ), ParentInfo( id='file#1', kind='file', name=relfile, root=testroot, relpath=relpath, parentid='<root>', ), ] expected = [{ 'rootid': '<root>', 'root': testroot, 'parents': [ { 'id': 'file#1', 'kind': 'file', 'name': relfile, 'relpath': relpath, 'parentid': '<root>', }, ], 'tests': [{ 'id': 'test#1', 'name': 'test_spam', 'source': '{}:{}'.format(relfile, 10), 'markers': [], 'parentid': 'file#1', }], }] report_discovered(tests, parents, _send=stub.send) self.maxDiff = None self.assertEqual(stub.calls, [ ('send', (expected, ), None), ])
def test_multiroot(self): # the first root testroot1 = fix_path("/a/b/c") relfile1 = "test_spam.py" alltests = [ SingleTestInfo( # missing "./": id=relfile1 + "::test_spam", name="test_spam", path=SingleTestPath( root=testroot1, relfile=fix_relpath(relfile1), func="test_spam", ), source="{}:{}".format(relfile1, 10), markers=[], # missing "./": parentid=relfile1, ), ] allparents = [ # missing "./": [ (relfile1, "test_spam.py", "file"), (".", testroot1, "folder"), ], ] # the second root testroot2 = fix_path("/x/y/z") relfile2 = fix_path("w/test_eggs.py") alltests.extend([ SingleTestInfo( id=relfile2 + "::BasicTests::test_first", name="test_first", path=SingleTestPath( root=testroot2, relfile=fix_relpath(relfile2), func="BasicTests.test_first", ), source="{}:{}".format(relfile2, 61), markers=[], parentid=relfile2 + "::BasicTests", ), ]) allparents.extend([ # missing "./", using pathsep: [ (relfile2 + "::BasicTests", "BasicTests", "suite"), (relfile2, "test_eggs.py", "file"), (fix_path("./w"), "w", "folder"), (".", testroot2, "folder"), ], ]) discovered = DiscoveredTests() for test, parents in zip(alltests, allparents): discovered.add_test(test, parents) tests = list(discovered) parents = discovered.parents self.maxDiff = None self.assertEqual( tests, [ # the first root SingleTestInfo( id="./test_spam.py::test_spam", name="test_spam", path=SingleTestPath( root=testroot1, relfile=fix_relpath(relfile1), func="test_spam", ), source="{}:{}".format(relfile1, 10), markers=[], parentid="./test_spam.py", ), # the secondroot SingleTestInfo( id="./w/test_eggs.py::BasicTests::test_first", name="test_first", path=SingleTestPath( root=testroot2, relfile=fix_relpath(relfile2), func="BasicTests.test_first", ), source="{}:{}".format(relfile2, 61), markers=[], parentid="./w/test_eggs.py::BasicTests", ), ], ) self.assertEqual( parents, [ # the first root ParentInfo( id=".", kind="folder", name=testroot1, ), ParentInfo( id="./test_spam.py", kind="file", name="test_spam.py", root=testroot1, relpath=fix_relpath(relfile1), parentid=".", ), # the secondroot ParentInfo( id=".", kind="folder", name=testroot2, ), ParentInfo( id="./w", kind="folder", name="w", root=testroot2, relpath=fix_path("./w"), parentid=".", ), ParentInfo( id="./w/test_eggs.py", kind="file", name="test_eggs.py", root=testroot2, relpath=fix_relpath(relfile2), parentid="./w", ), ParentInfo( id="./w/test_eggs.py::BasicTests", kind="suite", name="BasicTests", root=testroot2, parentid="./w/test_eggs.py", ), ], )
def test_list(self): testroot = fix_path('/a/b/c') relfile = fix_path('./test_spam.py') tests = [ TestInfo( # missing "./": id='test_spam.py::test_each[10-10]', name='test_each[10-10]', path=TestPath( root=testroot, relfile=relfile, func='test_each', sub=['[10-10]'], ), source='{}:{}'.format(relfile, 10), markers=None, # missing "./": parentid='test_spam.py::test_each', ), TestInfo( id='test_spam.py::All::BasicTests::test_first', name='test_first', path=TestPath( root=testroot, relfile=relfile, func='All.BasicTests.test_first', sub=None, ), source='{}:{}'.format(relfile, 62), markers=None, parentid='test_spam.py::All::BasicTests', ), ] allparents = [ [ (fix_path('./test_spam.py::test_each'), 'test_each', 'function'), (fix_path('./test_spam.py'), 'test_spam.py', 'file'), ('.', testroot, 'folder'), ], [ (fix_path('./test_spam.py::All::BasicTests'), 'BasicTests', 'suite'), (fix_path('./test_spam.py::All'), 'All', 'suite'), (fix_path('./test_spam.py'), 'test_spam.py', 'file'), ('.', testroot, 'folder'), ], ] expected = [ test._replace(id=_fix_nodeid(test.id), parentid=_fix_nodeid(test.parentid)) for test in tests ] discovered = DiscoveredTests() for test, parents in zip(tests, allparents): discovered.add_test(test, parents) size = len(discovered) items = [discovered[0], discovered[1]] snapshot = list(discovered) self.maxDiff = None self.assertEqual(size, 2) self.assertEqual(items, expected) self.assertEqual(snapshot, expected)
def test_basic(self): stub = StubSender() testroot = fix_path("/a/b/c") relfile = "test_spam.py" relpath = fix_relpath(relfile) tests = [ TestInfo( id="test#1", name="test_spam", path=TestPath( root=testroot, relfile=relfile, func="test_spam", ), source="{}:{}".format(relfile, 10), markers=[], parentid="file#1", ), ] parents = [ ParentInfo( id="<root>", kind="folder", name=testroot, ), ParentInfo( id="file#1", kind="file", name=relfile, root=testroot, relpath=relpath, parentid="<root>", ), ] expected = [{ "rootid": "<root>", "root": testroot, "parents": [ { "id": "file#1", "kind": "file", "name": relfile, "relpath": relpath, "parentid": "<root>", }, ], "tests": [{ "id": "test#1", "name": "test_spam", "source": "{}:{}".format(relfile, 10), "markers": [], "parentid": "file#1", }], }] report_discovered(tests, parents, _send=stub.send) self.maxDiff = None self.assertEqual(stub.calls, [ ("send", (expected, ), None), ])
def test_complex(self): """ /a/b/c/ test_ham.py MySuite test_x1 test_x2 /a/b/e/f/g/ w/ test_ham.py test_ham1 HamTests test_uh_oh test_whoa MoreHam test_yay sub1 sub2 sub3 test_eggs.py SpamTests test_okay x/ y/ a/ test_spam.py SpamTests test_okay b/ test_spam.py SpamTests test_okay test_spam.py SpamTests test_okay """ stub = StubSender() testroot = fix_path("/a/b/c") relfileid1 = "./test_ham.py" relfileid2 = "./test_spam.py" relfileid3 = "./w/test_ham.py" relfileid4 = "./w/test_eggs.py" relfileid5 = "./x/y/a/test_spam.py" relfileid6 = "./x/y/b/test_spam.py" tests = [ TestInfo( id=relfileid1 + "::MySuite::test_x1", name="test_x1", path=TestPath( root=testroot, relfile=fix_path(relfileid1), func="MySuite.test_x1", ), source="{}:{}".format(fix_path(relfileid1), 10), markers=None, parentid=relfileid1 + "::MySuite", ), TestInfo( id=relfileid1 + "::MySuite::test_x2", name="test_x2", path=TestPath( root=testroot, relfile=fix_path(relfileid1), func="MySuite.test_x2", ), source="{}:{}".format(fix_path(relfileid1), 21), markers=None, parentid=relfileid1 + "::MySuite", ), TestInfo( id=relfileid2 + "::SpamTests::test_okay", name="test_okay", path=TestPath( root=testroot, relfile=fix_path(relfileid2), func="SpamTests.test_okay", ), source="{}:{}".format(fix_path(relfileid2), 17), markers=None, parentid=relfileid2 + "::SpamTests", ), TestInfo( id=relfileid3 + "::test_ham1", name="test_ham1", path=TestPath( root=testroot, relfile=fix_path(relfileid3), func="test_ham1", ), source="{}:{}".format(fix_path(relfileid3), 8), markers=None, parentid=relfileid3, ), TestInfo( id=relfileid3 + "::HamTests::test_uh_oh", name="test_uh_oh", path=TestPath( root=testroot, relfile=fix_path(relfileid3), func="HamTests.test_uh_oh", ), source="{}:{}".format(fix_path(relfileid3), 19), markers=["expected-failure"], parentid=relfileid3 + "::HamTests", ), TestInfo( id=relfileid3 + "::HamTests::test_whoa", name="test_whoa", path=TestPath( root=testroot, relfile=fix_path(relfileid3), func="HamTests.test_whoa", ), source="{}:{}".format(fix_path(relfileid3), 35), markers=None, parentid=relfileid3 + "::HamTests", ), TestInfo( id=relfileid3 + "::MoreHam::test_yay[1-2]", name="test_yay[1-2]", path=TestPath( root=testroot, relfile=fix_path(relfileid3), func="MoreHam.test_yay", sub=["[1-2]"], ), source="{}:{}".format(fix_path(relfileid3), 57), markers=None, parentid=relfileid3 + "::MoreHam::test_yay", ), TestInfo( id=relfileid3 + "::MoreHam::test_yay[1-2][3-4]", name="test_yay[1-2][3-4]", path=TestPath( root=testroot, relfile=fix_path(relfileid3), func="MoreHam.test_yay", sub=["[1-2]", "[3=4]"], ), source="{}:{}".format(fix_path(relfileid3), 72), markers=None, parentid=relfileid3 + "::MoreHam::test_yay[1-2]", ), TestInfo( id=relfileid4 + "::SpamTests::test_okay", name="test_okay", path=TestPath( root=testroot, relfile=fix_path(relfileid4), func="SpamTests.test_okay", ), source="{}:{}".format(fix_path(relfileid4), 15), markers=None, parentid=relfileid4 + "::SpamTests", ), TestInfo( id=relfileid5 + "::SpamTests::test_okay", name="test_okay", path=TestPath( root=testroot, relfile=fix_path(relfileid5), func="SpamTests.test_okay", ), source="{}:{}".format(fix_path(relfileid5), 12), markers=None, parentid=relfileid5 + "::SpamTests", ), TestInfo( id=relfileid6 + "::SpamTests::test_okay", name="test_okay", path=TestPath( root=testroot, relfile=fix_path(relfileid6), func="SpamTests.test_okay", ), source="{}:{}".format(fix_path(relfileid6), 27), markers=None, parentid=relfileid6 + "::SpamTests", ), ] parents = [ ParentInfo( id=".", kind="folder", name=testroot, ), ParentInfo( id=relfileid1, kind="file", name="test_ham.py", root=testroot, relpath=fix_path(relfileid1), parentid=".", ), ParentInfo( id=relfileid1 + "::MySuite", kind="suite", name="MySuite", root=testroot, parentid=relfileid1, ), ParentInfo( id=relfileid2, kind="file", name="test_spam.py", root=testroot, relpath=fix_path(relfileid2), parentid=".", ), ParentInfo( id=relfileid2 + "::SpamTests", kind="suite", name="SpamTests", root=testroot, parentid=relfileid2, ), ParentInfo( id="./w", kind="folder", name="w", root=testroot, relpath=fix_path("./w"), parentid=".", ), ParentInfo( id=relfileid3, kind="file", name="test_ham.py", root=testroot, relpath=fix_path(relfileid3), parentid="./w", ), ParentInfo( id=relfileid3 + "::HamTests", kind="suite", name="HamTests", root=testroot, parentid=relfileid3, ), ParentInfo( id=relfileid3 + "::MoreHam", kind="suite", name="MoreHam", root=testroot, parentid=relfileid3, ), ParentInfo( id=relfileid3 + "::MoreHam::test_yay", kind="function", name="test_yay", root=testroot, parentid=relfileid3 + "::MoreHam", ), ParentInfo( id=relfileid3 + "::MoreHam::test_yay[1-2]", kind="subtest", name="test_yay[1-2]", root=testroot, parentid=relfileid3 + "::MoreHam::test_yay", ), ParentInfo( id=relfileid4, kind="file", name="test_eggs.py", root=testroot, relpath=fix_path(relfileid4), parentid="./w", ), ParentInfo( id=relfileid4 + "::SpamTests", kind="suite", name="SpamTests", root=testroot, parentid=relfileid4, ), ParentInfo( id="./x", kind="folder", name="x", root=testroot, relpath=fix_path("./x"), parentid=".", ), ParentInfo( id="./x/y", kind="folder", name="y", root=testroot, relpath=fix_path("./x/y"), parentid="./x", ), ParentInfo( id="./x/y/a", kind="folder", name="a", root=testroot, relpath=fix_path("./x/y/a"), parentid="./x/y", ), ParentInfo( id=relfileid5, kind="file", name="test_spam.py", root=testroot, relpath=fix_path(relfileid5), parentid="./x/y/a", ), ParentInfo( id=relfileid5 + "::SpamTests", kind="suite", name="SpamTests", root=testroot, parentid=relfileid5, ), ParentInfo( id="./x/y/b", kind="folder", name="b", root=testroot, relpath=fix_path("./x/y/b"), parentid="./x/y", ), ParentInfo( id=relfileid6, kind="file", name="test_spam.py", root=testroot, relpath=fix_path(relfileid6), parentid="./x/y/b", ), ParentInfo( id=relfileid6 + "::SpamTests", kind="suite", name="SpamTests", root=testroot, parentid=relfileid6, ), ] expected = [{ "rootid": ".", "root": testroot, "parents": [ { "id": relfileid1, "kind": "file", "name": "test_ham.py", "relpath": fix_path(relfileid1), "parentid": ".", }, { "id": relfileid1 + "::MySuite", "kind": "suite", "name": "MySuite", "parentid": relfileid1, }, { "id": relfileid2, "kind": "file", "name": "test_spam.py", "relpath": fix_path(relfileid2), "parentid": ".", }, { "id": relfileid2 + "::SpamTests", "kind": "suite", "name": "SpamTests", "parentid": relfileid2, }, { "id": "./w", "kind": "folder", "name": "w", "relpath": fix_path("./w"), "parentid": ".", }, { "id": relfileid3, "kind": "file", "name": "test_ham.py", "relpath": fix_path(relfileid3), "parentid": "./w", }, { "id": relfileid3 + "::HamTests", "kind": "suite", "name": "HamTests", "parentid": relfileid3, }, { "id": relfileid3 + "::MoreHam", "kind": "suite", "name": "MoreHam", "parentid": relfileid3, }, { "id": relfileid3 + "::MoreHam::test_yay", "kind": "function", "name": "test_yay", "parentid": relfileid3 + "::MoreHam", }, { "id": relfileid3 + "::MoreHam::test_yay[1-2]", "kind": "subtest", "name": "test_yay[1-2]", "parentid": relfileid3 + "::MoreHam::test_yay", }, { "id": relfileid4, "kind": "file", "name": "test_eggs.py", "relpath": fix_path(relfileid4), "parentid": "./w", }, { "id": relfileid4 + "::SpamTests", "kind": "suite", "name": "SpamTests", "parentid": relfileid4, }, { "id": "./x", "kind": "folder", "name": "x", "relpath": fix_path("./x"), "parentid": ".", }, { "id": "./x/y", "kind": "folder", "name": "y", "relpath": fix_path("./x/y"), "parentid": "./x", }, { "id": "./x/y/a", "kind": "folder", "name": "a", "relpath": fix_path("./x/y/a"), "parentid": "./x/y", }, { "id": relfileid5, "kind": "file", "name": "test_spam.py", "relpath": fix_path(relfileid5), "parentid": "./x/y/a", }, { "id": relfileid5 + "::SpamTests", "kind": "suite", "name": "SpamTests", "parentid": relfileid5, }, { "id": "./x/y/b", "kind": "folder", "name": "b", "relpath": fix_path("./x/y/b"), "parentid": "./x/y", }, { "id": relfileid6, "kind": "file", "name": "test_spam.py", "relpath": fix_path(relfileid6), "parentid": "./x/y/b", }, { "id": relfileid6 + "::SpamTests", "kind": "suite", "name": "SpamTests", "parentid": relfileid6, }, ], "tests": [ { "id": relfileid1 + "::MySuite::test_x1", "name": "test_x1", "source": "{}:{}".format(fix_path(relfileid1), 10), "markers": [], "parentid": relfileid1 + "::MySuite", }, { "id": relfileid1 + "::MySuite::test_x2", "name": "test_x2", "source": "{}:{}".format(fix_path(relfileid1), 21), "markers": [], "parentid": relfileid1 + "::MySuite", }, { "id": relfileid2 + "::SpamTests::test_okay", "name": "test_okay", "source": "{}:{}".format(fix_path(relfileid2), 17), "markers": [], "parentid": relfileid2 + "::SpamTests", }, { "id": relfileid3 + "::test_ham1", "name": "test_ham1", "source": "{}:{}".format(fix_path(relfileid3), 8), "markers": [], "parentid": relfileid3, }, { "id": relfileid3 + "::HamTests::test_uh_oh", "name": "test_uh_oh", "source": "{}:{}".format(fix_path(relfileid3), 19), "markers": ["expected-failure"], "parentid": relfileid3 + "::HamTests", }, { "id": relfileid3 + "::HamTests::test_whoa", "name": "test_whoa", "source": "{}:{}".format(fix_path(relfileid3), 35), "markers": [], "parentid": relfileid3 + "::HamTests", }, { "id": relfileid3 + "::MoreHam::test_yay[1-2]", "name": "test_yay[1-2]", "source": "{}:{}".format(fix_path(relfileid3), 57), "markers": [], "parentid": relfileid3 + "::MoreHam::test_yay", }, { "id": relfileid3 + "::MoreHam::test_yay[1-2][3-4]", "name": "test_yay[1-2][3-4]", "source": "{}:{}".format(fix_path(relfileid3), 72), "markers": [], "parentid": relfileid3 + "::MoreHam::test_yay[1-2]", }, { "id": relfileid4 + "::SpamTests::test_okay", "name": "test_okay", "source": "{}:{}".format(fix_path(relfileid4), 15), "markers": [], "parentid": relfileid4 + "::SpamTests", }, { "id": relfileid5 + "::SpamTests::test_okay", "name": "test_okay", "source": "{}:{}".format(fix_path(relfileid5), 12), "markers": [], "parentid": relfileid5 + "::SpamTests", }, { "id": relfileid6 + "::SpamTests::test_okay", "name": "test_okay", "source": "{}:{}".format(fix_path(relfileid6), 27), "markers": [], "parentid": relfileid6 + "::SpamTests", }, ], }] report_discovered(tests, parents, _send=stub.send) self.maxDiff = None self.assertEqual(stub.calls, [ ("send", (expected, ), None), ])
def test_doctest(self): testroot = fix_path('/a/b/c') doctestfile = fix_path('./x/test_doctest.txt') relfile = fix_path('./x/y/z/test_eggs.py') alltests = [ TestInfo( id=doctestfile + '::test_doctest.txt', name='test_doctest.txt', path=TestPath( root=testroot, relfile=doctestfile, func=None, ), source='{}:{}'.format(doctestfile, 0), markers=[], parentid=doctestfile, ), # With --doctest-modules TestInfo( id=relfile + '::test_eggs', name='test_eggs', path=TestPath( root=testroot, relfile=relfile, func=None, ), source='{}:{}'.format(relfile, 0), markers=[], parentid=relfile, ), TestInfo( id=relfile + '::test_eggs.TestSpam', name='test_eggs.TestSpam', path=TestPath( root=testroot, relfile=relfile, func=None, ), source='{}:{}'.format(relfile, 12), markers=[], parentid=relfile, ), TestInfo( id=relfile + '::test_eggs.TestSpam.TestEggs', name='test_eggs.TestSpam.TestEggs', path=TestPath( root=testroot, relfile=relfile, func=None, ), source='{}:{}'.format(relfile, 27), markers=[], parentid=relfile, ), ] allparents = [ [ (doctestfile, 'test_doctest.txt', 'file'), (fix_path('./x'), 'x', 'folder'), ('.', testroot, 'folder'), ], [ (relfile, 'test_eggs.py', 'file'), (fix_path('./x/y/z'), 'z', 'folder'), (fix_path('./x/y'), 'y', 'folder'), (fix_path('./x'), 'x', 'folder'), ('.', testroot, 'folder'), ], [ (relfile, 'test_eggs.py', 'file'), (fix_path('./x/y/z'), 'z', 'folder'), (fix_path('./x/y'), 'y', 'folder'), (fix_path('./x'), 'x', 'folder'), ('.', testroot, 'folder'), ], [ (relfile, 'test_eggs.py', 'file'), (fix_path('./x/y/z'), 'z', 'folder'), (fix_path('./x/y'), 'y', 'folder'), (fix_path('./x'), 'x', 'folder'), ('.', testroot, 'folder'), ], ] expected = [ test._replace(id=_fix_nodeid(test.id), parentid=_fix_nodeid(test.parentid)) for test in alltests ] discovered = DiscoveredTests() for test, parents in zip(alltests, allparents): discovered.add_test(test, parents) tests = list(discovered) parents = discovered.parents self.maxDiff = None self.assertEqual(tests, expected) self.assertEqual(parents, [ ParentInfo( id='.', kind='folder', name=testroot, ), ParentInfo( id='./x', kind='folder', name='x', root=testroot, relpath=fix_path('./x'), parentid='.', ), ParentInfo( id='./x/test_doctest.txt', kind='file', name='test_doctest.txt', root=testroot, relpath=fix_path(doctestfile), parentid='./x', ), ParentInfo( id='./x/y', kind='folder', name='y', root=testroot, relpath=fix_path('./x/y'), parentid='./x', ), ParentInfo( id='./x/y/z', kind='folder', name='z', root=testroot, relpath=fix_path('./x/y/z'), parentid='./x/y', ), ParentInfo( id='./x/y/z/test_eggs.py', kind='file', name='test_eggs.py', root=testroot, relpath=fix_relpath(relfile), parentid='./x/y/z', ), ])
def test_simple_complex(self): """ /a/b/c/ test_ham.py MySuite test_x1 test_x2 /a/b/e/f/g/ w/ test_ham.py test_ham1 HamTests test_uh_oh test_whoa MoreHam test_yay sub1 sub2 sub3 test_eggs.py SpamTests test_okay x/ y/ a/ test_spam.py SpamTests test_okay b/ test_spam.py SpamTests test_okay test_spam.py SpamTests test_okay """ stub = StubSender() testroot1 = fix_path("/a/b/c") relfile1 = fix_path("./test_ham.py") testroot2 = fix_path("/a/b/e/f/g") relfile2 = fix_path("./test_spam.py") relfile3 = fix_path("w/test_ham.py") relfile4 = fix_path("w/test_eggs.py") relfile5 = fix_path("x/y/a/test_spam.py") relfile6 = fix_path("x/y/b/test_spam.py") tests = [ # under first root folder TestInfo( id="test#1", name="test_x1", path=TestPath( root=testroot1, relfile=relfile1, func="MySuite.test_x1", sub=None, ), source="{}:{}".format(relfile1, 10), markers=None, parentid="suite#1", ), TestInfo( id="test#2", name="test_x2", path=TestPath( root=testroot1, relfile=relfile1, func="MySuite.test_x2", sub=None, ), source="{}:{}".format(relfile1, 21), markers=None, parentid="suite#1", ), # under second root folder TestInfo( id="test#3", name="test_okay", path=TestPath( root=testroot2, relfile=relfile2, func="SpamTests.test_okay", sub=None, ), source="{}:{}".format(relfile2, 17), markers=None, parentid="suite#2", ), TestInfo( id="test#4", name="test_ham1", path=TestPath( root=testroot2, relfile=relfile3, func="test_ham1", sub=None, ), source="{}:{}".format(relfile3, 8), markers=None, parentid="file#3", ), TestInfo( id="test#5", name="test_uh_oh", path=TestPath( root=testroot2, relfile=relfile3, func="HamTests.test_uh_oh", sub=None, ), source="{}:{}".format(relfile3, 19), markers=["expected-failure"], parentid="suite#3", ), TestInfo( id="test#6", name="test_whoa", path=TestPath( root=testroot2, relfile=relfile3, func="HamTests.test_whoa", sub=None, ), source="{}:{}".format(relfile3, 35), markers=None, parentid="suite#3", ), TestInfo( id="test#7", name="test_yay (sub1)", path=TestPath( root=testroot2, relfile=relfile3, func="MoreHam.test_yay", sub=["sub1"], ), source="{}:{}".format(relfile3, 57), markers=None, parentid="suite#4", ), TestInfo( id="test#8", name="test_yay (sub2) (sub3)", path=TestPath( root=testroot2, relfile=relfile3, func="MoreHam.test_yay", sub=["sub2", "sub3"], ), source="{}:{}".format(relfile3, 72), markers=None, parentid="suite#3", ), TestInfo( id="test#9", name="test_okay", path=TestPath( root=testroot2, relfile=relfile4, func="SpamTests.test_okay", sub=None, ), source="{}:{}".format(relfile4, 15), markers=None, parentid="suite#5", ), TestInfo( id="test#10", name="test_okay", path=TestPath( root=testroot2, relfile=relfile5, func="SpamTests.test_okay", sub=None, ), source="{}:{}".format(relfile5, 12), markers=None, parentid="suite#6", ), TestInfo( id="test#11", name="test_okay", path=TestPath( root=testroot2, relfile=relfile6, func="SpamTests.test_okay", sub=None, ), source="{}:{}".format(relfile6, 27), markers=None, parentid="suite#7", ), ] expected = [ { "id": "test#1", "name": "test_x1", "testroot": testroot1, "relfile": relfile1, "lineno": 10, "testfunc": "MySuite.test_x1", "subtest": None, "markers": [], }, { "id": "test#2", "name": "test_x2", "testroot": testroot1, "relfile": relfile1, "lineno": 21, "testfunc": "MySuite.test_x2", "subtest": None, "markers": [], }, { "id": "test#3", "name": "test_okay", "testroot": testroot2, "relfile": relfile2, "lineno": 17, "testfunc": "SpamTests.test_okay", "subtest": None, "markers": [], }, { "id": "test#4", "name": "test_ham1", "testroot": testroot2, "relfile": relfile3, "lineno": 8, "testfunc": "test_ham1", "subtest": None, "markers": [], }, { "id": "test#5", "name": "test_uh_oh", "testroot": testroot2, "relfile": relfile3, "lineno": 19, "testfunc": "HamTests.test_uh_oh", "subtest": None, "markers": ["expected-failure"], }, { "id": "test#6", "name": "test_whoa", "testroot": testroot2, "relfile": relfile3, "lineno": 35, "testfunc": "HamTests.test_whoa", "subtest": None, "markers": [], }, { "id": "test#7", "name": "test_yay (sub1)", "testroot": testroot2, "relfile": relfile3, "lineno": 57, "testfunc": "MoreHam.test_yay", "subtest": ["sub1"], "markers": [], }, { "id": "test#8", "name": "test_yay (sub2) (sub3)", "testroot": testroot2, "relfile": relfile3, "lineno": 72, "testfunc": "MoreHam.test_yay", "subtest": ["sub2", "sub3"], "markers": [], }, { "id": "test#9", "name": "test_okay", "testroot": testroot2, "relfile": relfile4, "lineno": 15, "testfunc": "SpamTests.test_okay", "subtest": None, "markers": [], }, { "id": "test#10", "name": "test_okay", "testroot": testroot2, "relfile": relfile5, "lineno": 12, "testfunc": "SpamTests.test_okay", "subtest": None, "markers": [], }, { "id": "test#11", "name": "test_okay", "testroot": testroot2, "relfile": relfile6, "lineno": 27, "testfunc": "SpamTests.test_okay", "subtest": None, "markers": [], }, ] parents = None report_discovered(tests, parents, simple=True, _send=stub.send) self.maxDiff = None self.assertEqual(stub.calls, [ ("send", (expected, ), None), ])
def test_simple_complex(self): """ /a/b/c/ test_ham.py MySuite test_x1 test_x2 /a/b/e/f/g/ w/ test_ham.py test_ham1 HamTests test_uh_oh test_whoa MoreHam test_yay sub1 sub2 sub3 test_eggs.py SpamTests test_okay x/ y/ a/ test_spam.py SpamTests test_okay b/ test_spam.py SpamTests test_okay test_spam.py SpamTests test_okay """ stub = StubSender() testroot1 = fix_path('/a/b/c') relfile1 = fix_path('./test_ham.py') testroot2 = fix_path('/a/b/e/f/g') relfile2 = fix_path('./test_spam.py') relfile3 = fix_path('w/test_ham.py') relfile4 = fix_path('w/test_eggs.py') relfile5 = fix_path('x/y/a/test_spam.py') relfile6 = fix_path('x/y/b/test_spam.py') tests = [ # under first root folder TestInfo( id='test#1', name='test_x1', path=TestPath( root=testroot1, relfile=relfile1, func='MySuite.test_x1', sub=None, ), source='{}:{}'.format(relfile1, 10), markers=None, parentid='suite#1', ), TestInfo( id='test#2', name='test_x2', path=TestPath( root=testroot1, relfile=relfile1, func='MySuite.test_x2', sub=None, ), source='{}:{}'.format(relfile1, 21), markers=None, parentid='suite#1', ), # under second root folder TestInfo( id='test#3', name='test_okay', path=TestPath( root=testroot2, relfile=relfile2, func='SpamTests.test_okay', sub=None, ), source='{}:{}'.format(relfile2, 17), markers=None, parentid='suite#2', ), TestInfo( id='test#4', name='test_ham1', path=TestPath( root=testroot2, relfile=relfile3, func='test_ham1', sub=None, ), source='{}:{}'.format(relfile3, 8), markers=None, parentid='file#3', ), TestInfo( id='test#5', name='test_uh_oh', path=TestPath( root=testroot2, relfile=relfile3, func='HamTests.test_uh_oh', sub=None, ), source='{}:{}'.format(relfile3, 19), markers=['expected-failure'], parentid='suite#3', ), TestInfo( id='test#6', name='test_whoa', path=TestPath( root=testroot2, relfile=relfile3, func='HamTests.test_whoa', sub=None, ), source='{}:{}'.format(relfile3, 35), markers=None, parentid='suite#3', ), TestInfo( id='test#7', name='test_yay (sub1)', path=TestPath( root=testroot2, relfile=relfile3, func='MoreHam.test_yay', sub=['sub1'], ), source='{}:{}'.format(relfile3, 57), markers=None, parentid='suite#4', ), TestInfo( id='test#8', name='test_yay (sub2) (sub3)', path=TestPath( root=testroot2, relfile=relfile3, func='MoreHam.test_yay', sub=['sub2', 'sub3'], ), source='{}:{}'.format(relfile3, 72), markers=None, parentid='suite#3', ), TestInfo( id='test#9', name='test_okay', path=TestPath( root=testroot2, relfile=relfile4, func='SpamTests.test_okay', sub=None, ), source='{}:{}'.format(relfile4, 15), markers=None, parentid='suite#5', ), TestInfo( id='test#10', name='test_okay', path=TestPath( root=testroot2, relfile=relfile5, func='SpamTests.test_okay', sub=None, ), source='{}:{}'.format(relfile5, 12), markers=None, parentid='suite#6', ), TestInfo( id='test#11', name='test_okay', path=TestPath( root=testroot2, relfile=relfile6, func='SpamTests.test_okay', sub=None, ), source='{}:{}'.format(relfile6, 27), markers=None, parentid='suite#7', ), ] expected = [{ 'id': 'test#1', 'name': 'test_x1', 'testroot': testroot1, 'relfile': relfile1, 'lineno': 10, 'testfunc': 'MySuite.test_x1', 'subtest': None, 'markers': [], }, { 'id': 'test#2', 'name': 'test_x2', 'testroot': testroot1, 'relfile': relfile1, 'lineno': 21, 'testfunc': 'MySuite.test_x2', 'subtest': None, 'markers': [], }, { 'id': 'test#3', 'name': 'test_okay', 'testroot': testroot2, 'relfile': relfile2, 'lineno': 17, 'testfunc': 'SpamTests.test_okay', 'subtest': None, 'markers': [], }, { 'id': 'test#4', 'name': 'test_ham1', 'testroot': testroot2, 'relfile': relfile3, 'lineno': 8, 'testfunc': 'test_ham1', 'subtest': None, 'markers': [], }, { 'id': 'test#5', 'name': 'test_uh_oh', 'testroot': testroot2, 'relfile': relfile3, 'lineno': 19, 'testfunc': 'HamTests.test_uh_oh', 'subtest': None, 'markers': ['expected-failure'], }, { 'id': 'test#6', 'name': 'test_whoa', 'testroot': testroot2, 'relfile': relfile3, 'lineno': 35, 'testfunc': 'HamTests.test_whoa', 'subtest': None, 'markers': [], }, { 'id': 'test#7', 'name': 'test_yay (sub1)', 'testroot': testroot2, 'relfile': relfile3, 'lineno': 57, 'testfunc': 'MoreHam.test_yay', 'subtest': ['sub1'], 'markers': [], }, { 'id': 'test#8', 'name': 'test_yay (sub2) (sub3)', 'testroot': testroot2, 'relfile': relfile3, 'lineno': 72, 'testfunc': 'MoreHam.test_yay', 'subtest': ['sub2', 'sub3'], 'markers': [], }, { 'id': 'test#9', 'name': 'test_okay', 'testroot': testroot2, 'relfile': relfile4, 'lineno': 15, 'testfunc': 'SpamTests.test_okay', 'subtest': None, 'markers': [], }, { 'id': 'test#10', 'name': 'test_okay', 'testroot': testroot2, 'relfile': relfile5, 'lineno': 12, 'testfunc': 'SpamTests.test_okay', 'subtest': None, 'markers': [], }, { 'id': 'test#11', 'name': 'test_okay', 'testroot': testroot2, 'relfile': relfile6, 'lineno': 27, 'testfunc': 'SpamTests.test_okay', 'subtest': None, 'markers': [], }] parents = None report_discovered(tests, parents, simple=True, _send=stub.send) self.maxDiff = None self.assertEqual(stub.calls, [ ('send', (expected, ), None), ])
def test_nested_suite_simple(self): testroot = fix_path("/a/b/c") relfile = fix_path("./test_eggs.py") alltests = [ SingleTestInfo( id=relfile + "::TestOuter::TestInner::test_spam", name="test_spam", path=SingleTestPath( root=testroot, relfile=relfile, func="TestOuter.TestInner.test_spam", ), source="{}:{}".format(relfile, 10), markers=None, parentid=relfile + "::TestOuter::TestInner", ), SingleTestInfo( id=relfile + "::TestOuter::TestInner::test_eggs", name="test_eggs", path=SingleTestPath( root=testroot, relfile=relfile, func="TestOuter.TestInner.test_eggs", ), source="{}:{}".format(relfile, 21), markers=None, parentid=relfile + "::TestOuter::TestInner", ), ] allparents = [ [ (relfile + "::TestOuter::TestInner", "TestInner", "suite"), (relfile + "::TestOuter", "TestOuter", "suite"), (relfile, "test_eggs.py", "file"), (".", testroot, "folder"), ], [ (relfile + "::TestOuter::TestInner", "TestInner", "suite"), (relfile + "::TestOuter", "TestOuter", "suite"), (relfile, "test_eggs.py", "file"), (".", testroot, "folder"), ], ] expected = [ test._replace(id=_fix_nodeid(test.id), parentid=_fix_nodeid(test.parentid)) for test in alltests ] discovered = DiscoveredTests() for test, parents in zip(alltests, allparents): discovered.add_test(test, parents) tests = list(discovered) parents = discovered.parents self.maxDiff = None self.assertEqual(tests, expected) self.assertEqual( parents, [ ParentInfo( id=".", kind="folder", name=testroot, ), ParentInfo( id="./test_eggs.py", kind="file", name="test_eggs.py", root=testroot, relpath=fix_relpath(relfile), parentid=".", ), ParentInfo( id="./test_eggs.py::TestOuter", kind="suite", name="TestOuter", root=testroot, parentid="./test_eggs.py", ), ParentInfo( id="./test_eggs.py::TestOuter::TestInner", kind="suite", name="TestInner", root=testroot, parentid="./test_eggs.py::TestOuter", ), ], )