PY-14221: Do not instantiate unittest runner explicitly

See Leonid's comments on https://github.com/JetBrains/teamcity-messages/issues/135
This commit is contained in:
Ilya.Kazakevich
2017-04-25 00:50:44 +03:00
parent dbf6d1c410
commit 778916e331
3 changed files with 52 additions and 3 deletions
@@ -30,8 +30,6 @@ if __name__ == '__main__':
additional_args += targets
args += additional_args
jb_doc_args("unittests", args)
test_runner = unittestpy.TeamcityTestRunner()
test_runner.buffer = True
# Working dir should be on path, that is how unittest work when launched from command line
sys.path.append(os.getcwd())
main(argv=args, module=None, testRunner=test_runner)
main(argv=args, module=None, testRunner=unittestpy.TeamcityTestRunner, buffer=True)
@@ -0,0 +1,11 @@
from unittest import TestCase
class SomeTestCase(TestCase):
def test_1_test(self):
assert False
def test_2_test(self):
pass
def test_3_test(self):
assert False
@@ -52,6 +52,46 @@ import static org.junit.Assert.assertEquals;
public final class PythonUnitTestingTest extends PyEnvTestCase {
/**
* tests failfast as example of argument
*/
@Test
public void testFailFast() throws Exception {
runPythonTest(new PyUnitTestProcessWithConsoleTestTask("testRunner/env/unit/failFast", "test_test.py") {
@NotNull
@Override
protected PyUnitTestProcessRunner createProcessRunner() throws Exception {
return new PyUnitTestProcessRunner(toFullPath(myScriptName), 1){
@Override
protected void configurationCreatedAndWillLaunch(@NotNull final PyUniversalUnitTestConfiguration configuration) throws IOException {
super.configurationCreatedAndWillLaunch(configuration);
configuration.setAdditionalArguments("-f"); //FailFast
}
};
}
@Override
protected void checkTestResults(@NotNull final PyUnitTestProcessRunner runner,
@NotNull final String stdout,
@NotNull final String stderr,
@NotNull final String all) {
Assert.assertEquals("Runner did not stop after first fail", 1, runner.getAllTestsCount());
runner.getFormattedTestTree();
Assert.assertEquals("Bad tree produced for failfast", "Test tree:\n" +
"[root]\n" +
".test_test\n" +
"..SomeTestCase\n" +
"...test_1_test(-)\n", runner.getFormattedTestTree());
}
});
}
/**
* tests with docstrings are reported as "test.name (text)" by unittest.
*/