From 9c434fd62ec17cfb709d21e7122cb89be4e22626 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 5 Aug 2019 14:08:01 -0600 Subject: [PATCH 1/4] Add a functional test for normcase on test results. --- .../.data/NormCase/tests/A/__init__.py | 0 .../.data/NormCase/tests/A/b/C/__init__.py | 0 .../.data/NormCase/tests/A/b/C/test_Spam.py | 3 ++ .../.data/NormCase/tests/A/b/__init__.py | 0 .../adapter/.data/NormCase/tests/__init__.py | 0 .../testing_tools/adapter/test_functional.py | 54 ++++++++++++++++++- 6 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/A/__init__.py create mode 100644 pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/A/b/C/__init__.py create mode 100644 pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/A/b/C/test_Spam.py create mode 100644 pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/A/b/__init__.py create mode 100644 pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/__init__.py diff --git a/pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/A/__init__.py b/pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/A/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/A/b/C/__init__.py b/pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/A/b/C/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/A/b/C/test_Spam.py b/pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/A/b/C/test_Spam.py new file mode 100644 index 000000000000..3501b9e118e5 --- /dev/null +++ b/pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/A/b/C/test_Spam.py @@ -0,0 +1,3 @@ + +def test_okay(): + assert True diff --git a/pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/A/b/__init__.py b/pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/A/b/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/__init__.py b/pythonFiles/tests/testing_tools/adapter/.data/NormCase/tests/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/pythonFiles/tests/testing_tools/adapter/test_functional.py b/pythonFiles/tests/testing_tools/adapter/test_functional.py index c5be00c6bc4a..209738d7f12f 100644 --- a/pythonFiles/tests/testing_tools/adapter/test_functional.py +++ b/pythonFiles/tests/testing_tools/adapter/test_functional.py @@ -21,8 +21,7 @@ def resolve_testroot(name): - projroot = os.path.normcase( - os.path.join(DATA_DIR, name)) + projroot = os.path.join(DATA_DIR, name) return projroot, os.path.join(projroot, 'tests') @@ -256,6 +255,57 @@ def test_discover_syntax_error(self): ) self.assertIn('(exit code 2)', cm.exception.output) + def test_discover_normcase(self): + projroot, testroot = resolve_testroot('NormCase') + + out = run_adapter('discover', 'pytest', + '--rootdir', projroot, + testroot) + result = json.loads(out) + + self.maxDiff = None + self.assertTrue(projroot.endswith('NormCase')) + fix_id = os.path.normcase + self.assertEqual(result, [{ + 'root': projroot, + 'rootid': '.', + 'parents': [ + {'id': fix_id('./tests'), + 'kind': 'folder', + 'name': 'tests', + 'parentid': '.', + }, + {'id': fix_id('./tests/A'), + 'kind': 'folder', + 'name': fix_id('A'), + 'parentid': fix_id('./tests'), + }, + {'id': fix_id('./tests/A/b'), + 'kind': 'folder', + 'name': 'b', + 'parentid': fix_id('./tests/A'), + }, + {'id': fix_id('./tests/A/b/C'), + 'kind': 'folder', + 'name': fix_id('C'), + 'parentid': fix_id('./tests/A/b'), + }, + {'id': fix_id('./tests/A/b/C/test_Spam.py'), + 'kind': 'file', + 'name': fix_id('test_Spam.py'), + 'parentid': fix_id('./tests/A/b/C'), + }, + ], + 'tests': [ + {'id': fix_id('./tests/A/b/C/test_Spam.py::test_okay'), + 'name': 'test_okay', + 'source': fix_path('./tests/A/b/C/test_Spam.py:2'), + 'markers': [], + 'parentid': fix_id('./tests/A/b/C/test_Spam.py'), + }, + ], + }]) + COMPLEX = { 'root': None, From d1464e83dc4cfb3210f9f65bd5fc604e372574e0 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 5 Aug 2019 14:10:04 -0600 Subject: [PATCH 2/4] Make sure we test normcase properly in the unit tests. --- .../testing_tools/adapter/pytest/test_discovery.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pythonFiles/tests/testing_tools/adapter/pytest/test_discovery.py b/pythonFiles/tests/testing_tools/adapter/pytest/test_discovery.py index c6b6f4a8033c..a70657a2915d 100644 --- a/pythonFiles/tests/testing_tools/adapter/pytest/test_discovery.py +++ b/pythonFiles/tests/testing_tools/adapter/pytest/test_discovery.py @@ -787,14 +787,14 @@ def test_windows(self): stub = Stub() discovered = StubDiscoveredTests(stub) session = StubPytestSession(stub) - testroot = r'c:\a\b\c' + testroot = r'C:\A\B\C' relfile = r'X\Y\Z\test_eggs.py' session.items = [ StubFunctionItem( stub, - nodeid='X/Y/Z/test_eggs.py::SpamTests::test_spam', + nodeid='x/y/z/test_eggs.py::SpamTests::test_spam', name='test_spam', - location=('x/y/z/test_eggs.py', 12, 'SpamTests.test_spam'), + location=('X/Y/Z/test_eggs.py', 12, 'SpamTests.test_spam'), fspath=testroot + '\\' + relfile, function=FakeFunc('test_spam'), ), @@ -825,12 +825,12 @@ def normcase(path): id=r'.\x\y\z\test_eggs.py::SpamTests::test_spam', name='test_spam', path=TestPath( - root=testroot, - relfile=r'.\X\Y\Z\test_eggs.py', + root=testroot, # not normalized + relfile=r'.\X\Y\Z\test_eggs.py', # not normalized func='SpamTests.test_spam', sub=None, ), - source=r'.\X\Y\Z\test_eggs.py:{}'.format(13), + source=r'.\X\Y\Z\test_eggs.py:{}'.format(13), # not normalized markers=None, parentid=r'.\x\y\z\test_eggs.py::SpamTests', ), From fd65fc0a9de9216f2f38a509881f534e3ae02c82 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 5 Aug 2019 14:42:23 -0600 Subject: [PATCH 3/4] Do not colorize pythonFiles/tests output in CI. --- build/ci/templates/test_phases.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/ci/templates/test_phases.yml b/build/ci/templates/test_phases.yml index f7edee7583e9..14e4ff315631 100644 --- a/build/ci/templates/test_phases.yml +++ b/build/ci/templates/test_phases.yml @@ -231,7 +231,7 @@ steps: # > python -m pip install -U -r build/test-requirements.txt # > python pythonFiles/tests/run_all.py --color=yes --junit-xml=python-tests-junit.xml - bash: | - python pythonFiles/tests/run_all.py --color=yes --junit-xml=$COMMON_TESTRESULTSDIRECTORY/python-tests-junit.xml + python pythonFiles/tests/run_all.py --color=no --junit-xml=$COMMON_TESTRESULTSDIRECTORY/python-tests-junit.xml displayName: 'Python unittests' condition: and(succeeded(), contains(variables['TestsToRun'], 'pythonUnitTests')) @@ -256,7 +256,7 @@ steps: # > python -m pip install -U -r build/test-requirements.txt # > python pythonFiles/tests/run_all.py --color=yes --junit-xml=python-tests-junit.xml - bash: | - python -m IPython pythonFiles/tests/run_all.py -- --color=yes --junit-xml=$COMMON_TESTRESULTSDIRECTORY/ipython-tests-junit.xml + python -m IPython pythonFiles/tests/run_all.py -- --color=no --junit-xml=$COMMON_TESTRESULTSDIRECTORY/ipython-tests-junit.xml displayName: 'Python ipython tests' condition: and(succeeded(), contains(variables['TestsToRun'], 'pythonIPythonTests')) From fad563a66e89fc5aa1dbd6d40ae890096bc5f332 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 5 Aug 2019 15:45:43 -0600 Subject: [PATCH 4/4] Always normcase the testroot when matching relfile. --- pythonFiles/testing_tools/adapter/pytest/_pytest_item.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py b/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py index 313ae599a98a..9bd3d9ff45e8 100644 --- a/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py +++ b/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py @@ -270,6 +270,7 @@ def _get_location(item, testroot, relfile, _normcase, _pathsep): def _matches_relfile(srcfile, testroot, relfile, _normcase, _pathsep): """Return True if "srcfile" matches the given relfile.""" + testroot = _normcase(testroot) srcfile = _normcase(srcfile) relfile = _normcase(relfile) if srcfile == relfile: