def test_basic(self): stub = StubSender() testroot = '/a/b/c'.replace('/', os.path.sep) relfile = 'test_spam.py' 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, parentid='<root>', ), ] expected = [{ 'rootid': '<root>', 'root': testroot, 'parents': [ {'id': 'file#1', 'kind': 'file', 'name': relfile, '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_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_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_add_test_simple(self): testroot = '/a/b/c'.replace('/', os.path.sep) test = TestInfo( id='test_spam.py::test_spam', name='test_spam', path=TestPath( root=testroot, relfile='test_spam.py', func='test_spam', ), source='{}:{}'.format('test_spam.py', 11), markers=[], parentid='test_spam.py', ) expected = test._replace(id=os.path.join('.', test.id), parentid=os.path.join('.', test.parentid)) discovered = DiscoveredTests() before = list(discovered), discovered.parents discovered.add_test(test, []) after = list(discovered), discovered.parents self.maxDiff = None self.assertEqual(before, ([], [])) self.assertEqual(after, ([expected], [ ParentInfo( id='.', kind='folder', name=testroot, ), ParentInfo( id=os.path.join('.', 'test_spam.py'), kind='file', name='test_spam.py', root=testroot, parentid='.', ), ]))
def test_parents(self): testroot = '/a/b/c'.replace('/', os.path.sep) relfile = 'x/y/z/test_spam.py'.replace('/', os.path.sep) relfileid = os.path.join('.', relfile) tests = [ TestInfo( id=relfile + '::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, parentid=relfile + '::test_each', ), TestInfo( id=relfile + '::All::BasicTests::test_first', name='test_first', path=TestPath( root=testroot, relfile=relfile, func='All.BasicTests.test_first', sub=None, ), source='{}:{}'.format(relfile, 61), markers=None, parentid=relfile + '::All::BasicTests', ), ] allsuiteids = [ [], [relfile + '::All', relfile + '::All::BasicTests', ], ] discovered = DiscoveredTests() for test, suiteids in zip(tests, allsuiteids): discovered.add_test(test, suiteids) parents = discovered.parents self.maxDiff = None self.assertEqual(parents, [ ParentInfo( id='.', kind='folder', name=testroot, ), ParentInfo( id='./x'.replace('/', os.path.sep), kind='folder', name='x', root=testroot, parentid='.', ), ParentInfo( id='./x/y'.replace('/', os.path.sep), kind='folder', name='y', root=testroot, parentid='./x'.replace('/', os.path.sep), ), ParentInfo( id='./x/y/z'.replace('/', os.path.sep), kind='folder', name='z', root=testroot, parentid='./x/y'.replace('/', os.path.sep), ), ParentInfo( id=relfileid, kind='file', name=os.path.basename(relfile), root=testroot, parentid=os.path.dirname(relfileid), ), ParentInfo( id=relfileid + '::All', kind='suite', name='All', root=testroot, parentid=relfileid, ), ParentInfo( id=relfileid + '::All::BasicTests', kind='suite', name='BasicTests', root=testroot, parentid=relfileid + '::All', ), ParentInfo( id=relfileid + '::test_each', kind='function', name='test_each', root=testroot, parentid=relfileid, ), ])
def test_nested_suite_simple(self): stub = Stub() discovered = StubDiscoveredTests(stub) session = StubPytestSession(stub) testroot = '/a/b/c'.replace('/', os.path.sep) relfile = './test_eggs.py'.replace('/', os.path.sep) 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', ), ] allsuiteids = [ [relfile + '::TestOuter', relfile + '::TestOuter::TestInner', ], [relfile + '::TestOuter', relfile + '::TestOuter::TestInner', ], ] discovered = DiscoveredTests() for test, suiteids in zip(alltests, allsuiteids): discovered.add_test(test, suiteids) tests = list(discovered) parents = discovered.parents self.maxDiff = None self.assertEqual(tests, alltests) self.assertEqual(parents, [ ParentInfo( id='.', kind='folder', name=testroot, ), ParentInfo( id=relfile, kind='file', name=os.path.basename(relfile), root=testroot, parentid=os.path.dirname(relfile), ), ParentInfo( id=relfile + '::TestOuter', kind='suite', name='TestOuter', root=testroot, parentid=relfile, ), ParentInfo( id=relfile + '::TestOuter::TestInner', kind='suite', name='TestInner', root=testroot, parentid=relfile + '::TestOuter', ), ])
def test_doctest(self): stub = Stub() testroot = '/a/b/c'.replace('/', os.path.sep) doctestfile = './x/test_doctest.txt'.replace('/', os.path.sep) relfile = './x/y/z/test_eggs.py'.replace('/', os.path.sep) 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, ), ] discovered = DiscoveredTests() for test in alltests: discovered.add_test(test, []) tests = list(discovered) parents = discovered.parents self.maxDiff = None self.assertEqual(tests, alltests) self.assertEqual(parents, [ ParentInfo( id='.', kind='folder', name=testroot, ), ParentInfo( id='./x'.replace('/', os.path.sep), kind='folder', name='x', root=testroot, parentid='.', ), ParentInfo( id=doctestfile, kind='file', name=os.path.basename(doctestfile), root=testroot, parentid=os.path.dirname(doctestfile), ), ParentInfo( id='./x/y'.replace('/', os.path.sep), kind='folder', name='y', root=testroot, parentid='./x'.replace('/', os.path.sep), ), ParentInfo( id='./x/y/z'.replace('/', os.path.sep), kind='folder', name='z', root=testroot, parentid='./x/y'.replace('/', os.path.sep), ), ParentInfo( id=relfile, kind='file', name=os.path.basename(relfile), root=testroot, parentid=os.path.dirname(relfile), ), ])
def test_multiroot(self): # the first root testroot1 = '/a/b/c'.replace('/', os.path.sep) relfile1 = 'test_spam.py' relfileid1 = os.path.join('.', relfile1) alltests = [ TestInfo( id=relfile1 + '::test_spam', name='test_spam', path=TestPath( root=testroot1, relfile=relfile1, func='test_spam', ), source='{}:{}'.format(relfile1, 10), markers=[], parentid=relfile1, ), ] allsuiteids = [ [], ] # the second root testroot2 = '/x/y/z'.replace('/', os.path.sep) relfile2 = 'w/test_eggs.py' relfileid2 = os.path.join('.', relfile2) alltests.extend([ TestInfo( id=relfile2 + 'BasicTests::test_first', name='test_first', path=TestPath( root=testroot2, relfile=relfile2, func='BasicTests.test_first', ), source='{}:{}'.format(relfile2, 61), markers=[], parentid=relfile2 + '::BasicTests', ), ]) allsuiteids.extend([ [relfile2 + '::BasicTests', ], ]) discovered = DiscoveredTests() for test, suiteids in zip(alltests, allsuiteids): discovered.add_test(test, suiteids) tests = list(discovered) parents = discovered.parents self.maxDiff = None self.assertEqual(tests, [ # the first root TestInfo( id=relfileid1 + '::test_spam', name='test_spam', path=TestPath( root=testroot1, relfile=relfile1, func='test_spam', ), source='{}:{}'.format(relfile1, 10), markers=[], parentid=relfileid1, ), # the secondroot 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', ), ]) self.assertEqual(parents, [ # the first root ParentInfo( id='.', kind='folder', name=testroot1, ), ParentInfo( id=relfileid1, kind='file', name=os.path.basename(relfile1), root=testroot1, parentid=os.path.dirname(relfileid1), ), # the secondroot ParentInfo( id='.', kind='folder', name=testroot2, ), ParentInfo( id='./w'.replace('/', os.path.sep), kind='folder', name='w', root=testroot2, parentid='.', ), ParentInfo( id=relfileid2, kind='file', name=os.path.basename(relfile2), root=testroot2, parentid=os.path.dirname(relfileid2), ), ParentInfo( id=relfileid2 + '::BasicTests', kind='suite', name='BasicTests', root=testroot2, parentid=relfileid2, ), ])
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_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_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_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_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", ), ], )
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_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_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_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 = '/a/b/c'.replace('/', os.path.sep) relfile1 = './test_ham.py'.replace('/', os.path.sep) relfile2 = './test_spam.py'.replace('/', os.path.sep) relfile3 = './w/test_ham.py'.replace('/', os.path.sep) relfile4 = './w/test_eggs.py'.replace('/', os.path.sep) relfile5 = './x/y/a/test_spam.py'.replace('/', os.path.sep) relfile6 = './x/y/b/test_spam.py'.replace('/', os.path.sep) tests = [ TestInfo( id=relfile1 + '::MySuite::test_x1', name='test_x1', path=TestPath( root=testroot, relfile=relfile1, func='MySuite.test_x1', ), source='{}:{}'.format(relfile1, 10), markers=None, parentid=relfile1 + '::MySuite', ), TestInfo( id=relfile1 + '::MySuite::test_x2', name='test_x2', path=TestPath( root=testroot, relfile=relfile1, func='MySuite.test_x2', ), source='{}:{}'.format(relfile1, 21), markers=None, parentid=relfile1 + '::MySuite', ), TestInfo( id=relfile2 + '::SpamTests::test_okay', name='test_okay', path=TestPath( root=testroot, relfile=relfile2, func='SpamTests.test_okay', ), source='{}:{}'.format(relfile2, 17), markers=None, parentid=relfile2 + '::SpamTests', ), TestInfo( id=relfile3 + '::test_ham1', name='test_ham1', path=TestPath( root=testroot, relfile=relfile3, func='test_ham1', ), source='{}:{}'.format(relfile3, 8), markers=None, parentid=relfile3, ), TestInfo( id=relfile3 + '::HamTests::test_uh_oh', name='test_uh_oh', path=TestPath( root=testroot, relfile=relfile3, func='HamTests.test_uh_oh', ), source='{}:{}'.format(relfile3, 19), markers=['expected-failure'], parentid=relfile3 + '::HamTests', ), TestInfo( id=relfile3 + '::HamTests::test_whoa', name='test_whoa', path=TestPath( root=testroot, relfile=relfile3, func='HamTests.test_whoa', ), source='{}:{}'.format(relfile3, 35), markers=None, parentid=relfile3 + '::HamTests', ), TestInfo( id=relfile3 + '::MoreHam::test_yay[1-2]', name='test_yay[1-2]', path=TestPath( root=testroot, relfile=relfile3, func='MoreHam.test_yay', sub=['[1-2]'], ), source='{}:{}'.format(relfile3, 57), markers=None, parentid=relfile3 + '::MoreHam::test_yay', ), TestInfo( id=relfile3 + '::MoreHam::test_yay[1-2][3-4]', name='test_yay[1-2][3-4]', path=TestPath( root=testroot, relfile=relfile3, func='MoreHam.test_yay', sub=['[1-2]', '[3=4]'], ), source='{}:{}'.format(relfile3, 72), markers=None, parentid=relfile3 + '::MoreHam::test_yay[1-2]', ), TestInfo( id=relfile4 + '::SpamTests::test_okay', name='test_okay', path=TestPath( root=testroot, relfile=relfile4, func='SpamTests.test_okay', ), source='{}:{}'.format(relfile4, 15), markers=None, parentid=relfile4 + '::SpamTests', ), TestInfo( id=relfile5 + '::SpamTests::test_okay', name='test_okay', path=TestPath( root=testroot, relfile=relfile5, func='SpamTests.test_okay', ), source='{}:{}'.format(relfile5, 12), markers=None, parentid=relfile5 + '::SpamTests', ), TestInfo( id=relfile6 + '::SpamTests::test_okay', name='test_okay', path=TestPath( root=testroot, relfile=relfile6, func='SpamTests.test_okay', ), source='{}:{}'.format(relfile6, 27), markers=None, parentid=relfile6 + '::SpamTests', ), ] parents = [ ParentInfo( id='.', kind='folder', name=testroot, ), ParentInfo( id=relfile1, kind='file', name=os.path.basename(relfile1), root=testroot, parentid='.', ), ParentInfo( id=relfile1 + '::MySuite', kind='suite', name='MySuite', root=testroot, parentid=relfile1, ), ParentInfo( id=relfile2, kind='file', name=os.path.basename(relfile2), root=testroot, parentid='.', ), ParentInfo( id=relfile2 + '::SpamTests', kind='suite', name='SpamTests', root=testroot, parentid=relfile2, ), ParentInfo( id='./w'.replace('/', os.path.sep), kind='folder', name='w', root=testroot, parentid='.', ), ParentInfo( id=relfile3, kind='file', name=os.path.basename(relfile3), root=testroot, parentid=os.path.dirname(relfile3), ), ParentInfo( id=relfile3 + '::HamTests', kind='suite', name='HamTests', root=testroot, parentid=relfile3, ), ParentInfo( id=relfile3 + '::MoreHam', kind='suite', name='MoreHam', root=testroot, parentid=relfile3, ), ParentInfo( id=relfile3 + '::MoreHam::test_yay', kind='function', name='test_yay', root=testroot, parentid=relfile3 + '::MoreHam', ), ParentInfo( id=relfile3 + '::MoreHam::test_yay[1-2]', kind='subtest', name='test_yay[1-2]', root=testroot, parentid=relfile3 + '::MoreHam::test_yay', ), ParentInfo( id=relfile4, kind='file', name=os.path.basename(relfile4), root=testroot, parentid=os.path.dirname(relfile4), ), ParentInfo( id=relfile4 + '::SpamTests', kind='suite', name='SpamTests', root=testroot, parentid=relfile4, ), ParentInfo( id='./x'.replace('/', os.path.sep), kind='folder', name='x', root=testroot, parentid='.', ), ParentInfo( id='./x/y'.replace('/', os.path.sep), kind='folder', name='y', root=testroot, parentid='./x'.replace('/', os.path.sep), ), ParentInfo( id='./x/y/a'.replace('/', os.path.sep), kind='folder', name='a', root=testroot, parentid='./x/y'.replace('/', os.path.sep), ), ParentInfo( id=relfile5, kind='file', name=os.path.basename(relfile5), root=testroot, parentid=os.path.dirname(relfile5), ), ParentInfo( id=relfile5 + '::SpamTests', kind='suite', name='SpamTests', root=testroot, parentid=relfile5, ), ParentInfo( id='./x/y/b'.replace('/', os.path.sep), kind='folder', name='b', root=testroot, parentid='./x/y'.replace('/', os.path.sep), ), ParentInfo( id=relfile6, kind='file', name=os.path.basename(relfile6), root=testroot, parentid=os.path.dirname(relfile6), ), ParentInfo( id=relfile6 + '::SpamTests', kind='suite', name='SpamTests', root=testroot, parentid=relfile6, ), ] expected = [{ 'rootid': '.', 'root': testroot, 'parents': [ {'id': relfile1, 'kind': 'file', 'name': os.path.basename(relfile1), 'parentid': '.', }, {'id': relfile1 + '::MySuite', 'kind': 'suite', 'name': 'MySuite', 'parentid': relfile1, }, {'id': relfile2, 'kind': 'file', 'name': os.path.basename(relfile2), 'parentid': '.', }, {'id': relfile2 + '::SpamTests', 'kind': 'suite', 'name': 'SpamTests', 'parentid': relfile2, }, {'id': './w'.replace('/', os.path.sep), 'kind': 'folder', 'name': 'w', 'parentid': '.', }, {'id': relfile3, 'kind': 'file', 'name': os.path.basename(relfile3), 'parentid': os.path.dirname(relfile3), }, {'id': relfile3 + '::HamTests', 'kind': 'suite', 'name': 'HamTests', 'parentid': relfile3, }, {'id': relfile3 + '::MoreHam', 'kind': 'suite', 'name': 'MoreHam', 'parentid': relfile3, }, {'id': relfile3 + '::MoreHam::test_yay', 'kind': 'function', 'name': 'test_yay', 'parentid': relfile3 + '::MoreHam', }, {'id': relfile3 + '::MoreHam::test_yay[1-2]', 'kind': 'subtest', 'name': 'test_yay[1-2]', 'parentid': relfile3 + '::MoreHam::test_yay', }, {'id': relfile4, 'kind': 'file', 'name': os.path.basename(relfile4), 'parentid': os.path.dirname(relfile4), }, {'id': relfile4 + '::SpamTests', 'kind': 'suite', 'name': 'SpamTests', 'parentid': relfile4, }, {'id': './x'.replace('/', os.path.sep), 'kind': 'folder', 'name': 'x', 'parentid': '.', }, {'id': './x/y'.replace('/', os.path.sep), 'kind': 'folder', 'name': 'y', 'parentid': './x'.replace('/', os.path.sep), }, {'id': './x/y/a'.replace('/', os.path.sep), 'kind': 'folder', 'name': 'a', 'parentid': './x/y'.replace('/', os.path.sep), }, {'id': relfile5, 'kind': 'file', 'name': os.path.basename(relfile5), 'parentid': os.path.dirname(relfile5), }, {'id': relfile5 + '::SpamTests', 'kind': 'suite', 'name': 'SpamTests', 'parentid': relfile5, }, {'id': './x/y/b'.replace('/', os.path.sep), 'kind': 'folder', 'name': 'b', 'parentid': './x/y'.replace('/', os.path.sep), }, {'id': relfile6, 'kind': 'file', 'name': os.path.basename(relfile6), 'parentid': os.path.dirname(relfile6), }, {'id': relfile6 + '::SpamTests', 'kind': 'suite', 'name': 'SpamTests', 'parentid': relfile6, }, ], 'tests': [ {'id': relfile1 + '::MySuite::test_x1', 'name': 'test_x1', 'source': '{}:{}'.format(relfile1, 10), 'markers': [], 'parentid': relfile1 + '::MySuite', }, {'id': relfile1 + '::MySuite::test_x2', 'name': 'test_x2', 'source': '{}:{}'.format(relfile1, 21), 'markers': [], 'parentid': relfile1 + '::MySuite', }, {'id': relfile2 + '::SpamTests::test_okay', 'name': 'test_okay', 'source': '{}:{}'.format(relfile2, 17), 'markers': [], 'parentid': relfile2 + '::SpamTests', }, {'id': relfile3 + '::test_ham1', 'name': 'test_ham1', 'source': '{}:{}'.format(relfile3, 8), 'markers': [], 'parentid': relfile3, }, {'id': relfile3 + '::HamTests::test_uh_oh', 'name': 'test_uh_oh', 'source': '{}:{}'.format(relfile3, 19), 'markers': ['expected-failure'], 'parentid': relfile3 + '::HamTests', }, {'id': relfile3 + '::HamTests::test_whoa', 'name': 'test_whoa', 'source': '{}:{}'.format(relfile3, 35), 'markers': [], 'parentid': relfile3 + '::HamTests', }, {'id': relfile3 + '::MoreHam::test_yay[1-2]', 'name': 'test_yay[1-2]', 'source': '{}:{}'.format(relfile3, 57), 'markers': [], 'parentid': relfile3 + '::MoreHam::test_yay', }, {'id': relfile3 + '::MoreHam::test_yay[1-2][3-4]', 'name': 'test_yay[1-2][3-4]', 'source': '{}:{}'.format(relfile3, 72), 'markers': [], 'parentid': relfile3 + '::MoreHam::test_yay[1-2]', }, {'id': relfile4 + '::SpamTests::test_okay', 'name': 'test_okay', 'source': '{}:{}'.format(relfile4, 15), 'markers': [], 'parentid': relfile4 + '::SpamTests', }, {'id': relfile5 + '::SpamTests::test_okay', 'name': 'test_okay', 'source': '{}:{}'.format(relfile5, 12), 'markers': [], 'parentid': relfile5 + '::SpamTests', }, {'id': relfile6 + '::SpamTests::test_okay', 'name': 'test_okay', 'source': '{}:{}'.format(relfile6, 27), 'markers': [], 'parentid': relfile6 + '::SpamTests', }, ], }] 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 = [ 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 = '/a/b/c'.replace('/', os.path.sep) relfile1 = 'test_spam.py' relfileid1 = os.path.join('.', relfile1) 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=os.path.basename(relfile1), root=testroot1, parentid=os.path.dirname(relfileid1), ), ] expected = [ {'rootid': '.', 'root': testroot1, 'parents': [ {'id': relfileid1, 'kind': 'file', 'name': relfile1, 'parentid': '.', }, ], 'tests': [{ 'id': relfileid1 + '::test_spam', 'name': 'test_spam', 'source': '{}:{}'.format(relfile1, 10), 'markers': [], 'parentid': relfileid1, }], }, ] # the second root testroot2 = '/x/y/z'.replace('/', os.path.sep) relfile2 = 'w/test_eggs.py' relfileid2 = os.path.join('.', relfile2) 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'.replace('/', os.path.sep), kind='folder', name='w', root=testroot2, parentid='.', ), ParentInfo( id=relfileid2, kind='file', name=os.path.basename(relfile2), root=testroot2, parentid=os.path.dirname(relfileid2), ), ParentInfo( id=relfileid2 + '::BasicTests', kind='suite', name='BasicTests', root=testroot2, parentid=relfileid2, ), ]) expected.extend([ {'rootid': '.', 'root': testroot2, 'parents': [ {'id': os.path.dirname(relfileid2), 'kind': 'folder', 'name': 'w', 'parentid': '.', }, {'id': relfileid2, 'kind': 'file', 'name': os.path.basename(relfile2), 'parentid': os.path.dirname(relfileid2), }, {'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_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_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", ), ], )