From 6eceabff483dcf1ea69f18aba9f7963d75b979e7 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Tue, 23 Apr 2019 23:17:59 +0300 Subject: [PATCH] PY-35394: Don't break when setupClass reported several times. With xdist, setupClass may be reported several times (one for each test). Next report leads to error since it is already reported as closed. We ignore setup methods: there is no sane place to display them in the test tree, anyway. GitOrigin-RevId: 3c7bcf2f3942e78fcbfba5fb0cae1cbdb2c92730 --- .../pycharm/_jb_parallel_tree_manager.py | 7 ++-- python/helpers/pycharm/_jb_runner_tools.py | 4 +++ python/setup-test-environment/build.gradle | 4 +-- .../env/pytest/parallel/test_parallel.py | 10 ++++++ .../python/testing/PythonPyTestingTest.java | 33 +++++++++++++++++++ 5 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 python/testData/testRunner/env/pytest/parallel/test_parallel.py diff --git a/python/helpers/pycharm/_jb_parallel_tree_manager.py b/python/helpers/pycharm/_jb_parallel_tree_manager.py index 4116383840c1..3b7e45d639cc 100644 --- a/python/helpers/pycharm/_jb_parallel_tree_manager.py +++ b/python/helpers/pycharm/_jb_parallel_tree_manager.py @@ -64,6 +64,9 @@ class ParallelTreeManager(object): def get_node_ids(self, test_name): """ - :return: (current_node_id, parent_node_id) + :return: (current_node_id, parent_node_id) or None, None if message must be ignored """ - return self._branches[tuple(test_name.split("."))] + try: + return self._branches[tuple(test_name.split("."))] + except KeyError: + return None, None diff --git a/python/helpers/pycharm/_jb_runner_tools.py b/python/helpers/pycharm/_jb_runner_tools.py index 892bb6e18da5..4a5d4cabcd7e 100644 --- a/python/helpers/pycharm/_jb_runner_tools.py +++ b/python/helpers/pycharm/_jb_runner_tools.py @@ -101,6 +101,8 @@ class NewTeamcityServiceMessages(_old_service_messages): return current, parent = _TREE_MANAGER_HOLDER.manager.get_node_ids(properties["name"]) + if not current and not parent: + return # Shortcut for name try: properties["name"] = str(properties["name"]).split(".")[-1] @@ -189,6 +191,8 @@ class NewTeamcityServiceMessages(_old_service_messages): def _write_finished_message(): # testName, captureStandardOutput, flowId current, parent = _TREE_MANAGER_HOLDER.manager.get_node_ids(testName) + if not current and not parent: + return args = {"nodeId": current, "parentNodeId": parent, "name": testName} # TODO: Doc copy/paste with parent, extract diff --git a/python/setup-test-environment/build.gradle b/python/setup-test-environment/build.gradle index abbb53b4e0ae..a0216d5d39ce 100644 --- a/python/setup-test-environment/build.gradle +++ b/python/setup-test-environment/build.gradle @@ -98,8 +98,8 @@ envs { createPython("py35_django22_full", "3.5.4", - ["ipython==2.1", "django==2.2", "behave", "jinja2", "tox>=2.0", "nose", "pytest", "django-nose", "behave-django"], - "python3.4\npython3\nipython\nipython200\nskeletons\ndjango\nbehave\ntox\njinja2\npython34\npackaging\npytest\nnose\ndjango-nose\nbehave-django\ndjango2", + ["ipython==2.1", "django==2.2", "behave", "jinja2", "tox>=2.0", "nose", "pytest", "django-nose", "behave-django", "pytest-xdist"], + "python3.4\npython3\nipython\nipython200\nskeletons\ndjango\nbehave\ntox\njinja2\npython34\npackaging\npytest\nnose\ndjango-nose\nbehave-django\ndjango2\nxdist", true) createPython("py36_django2_1", diff --git a/python/testData/testRunner/env/pytest/parallel/test_parallel.py b/python/testData/testRunner/env/pytest/parallel/test_parallel.py new file mode 100644 index 000000000000..b6956b612361 --- /dev/null +++ b/python/testData/testRunner/env/pytest/parallel/test_parallel.py @@ -0,0 +1,10 @@ +import unittest + + +class ExampleTestCase(unittest.TestCase): + @classmethod + def setUpClass(cls) -> None: + print('2') + + def test_example(self): + assert 1 == 1 \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/env/python/testing/PythonPyTestingTest.java b/python/testSrc/com/jetbrains/env/python/testing/PythonPyTestingTest.java index c04e188b03fa..bfba29d32ad9 100644 --- a/python/testSrc/com/jetbrains/env/python/testing/PythonPyTestingTest.java +++ b/python/testSrc/com/jetbrains/env/python/testing/PythonPyTestingTest.java @@ -286,6 +286,39 @@ public final class PythonPyTestingTest extends PyEnvTestCase { } + @Test + @EnvTestTagsRequired(tags = "xdist") + public void testParallelWithSetup() { + runPythonTest( + new PyProcessWithConsoleTestTask("/testRunner/env/pytest/parallel", SdkCreationType.EMPTY_SDK) { + + @NotNull + @Override + protected PyTestTestProcessRunner createProcessRunner() { + return new PyTestTestProcessRunner("test_parallel.py", 0) { + @Override + protected void configurationCreatedAndWillLaunch(@NotNull PyTestConfiguration configuration) throws IOException { + super.configurationCreatedAndWillLaunch(configuration); + configuration.setAdditionalArguments("-n 4"); + } + }; + } + + @Override + protected void checkTestResults(@NotNull PyTestTestProcessRunner runner, + @NotNull String stdout, + @NotNull String stderr, + @NotNull String all, int exitCode) { + Assert.assertThat("xdist not launched?", all, Matchers.containsString("xdist")); + Assert.assertEquals("Test tree:\n" + + "[root](+)\n" + + ".test_parallel(+)\n" + + "..ExampleTestCase(+)\n" + + "...test_example(+)\n", runner.getFormattedTestTree()); + } + }); + } + // Ensure test survives patched strftime @Test public void testMonkeyPatch() {