PY-27636: Add cwd to pythonpath's head instead of tail

current workdir must be inserted at position 0, not at
the last position because local files (like "test.py") must have priority over site-lib
This commit is contained in:
Ilya.Kazakevich
2018-04-04 23:55:25 +03:00
parent 5d35843984
commit 9a82e20592
3 changed files with 54 additions and 17 deletions

View File

@@ -31,5 +31,5 @@ if __name__ == '__main__':
args += additional_args
jb_doc_args("unittests", args)
# Working dir should be on path, that is how unittest work when launched from command line
sys.path.append(os.getcwd())
sys.path.insert(0, os.getcwd())
main(argv=args, module=None, testRunner=unittestpy.TeamcityTestRunner, buffer=not JB_DISABLE_BUFFERING)

View File

@@ -0,0 +1,7 @@
import unittest
class DemoTest(unittest.TestCase):
def test_1(self):
self.assertTrue(True)

View File

@@ -140,6 +140,36 @@ public final class PythonUnitTestingTest extends PythonUnitTestingLikeTest<PyUni
});
}
@Test
public void testSysPathOrder() {
runPythonTest(new PyUnitTestProcessWithConsoleTestTask("testRunner/env/unit/sysPath", "test.py") {
@NotNull
@Override
protected PyUnitTestProcessRunner createProcessRunner() throws Exception {
return new PyUnitTestProcessRunner("", 0) {
@Override
protected void configurationCreatedAndWillLaunch(@NotNull final PyUnitTestConfiguration configuration) throws IOException {
super.configurationCreatedAndWillLaunch(configuration);
configuration.getTarget().setTargetType(PyRunTargetVariant.PYTHON);
configuration.getTarget().setTarget("test.DemoTest");
final VirtualFile subfolder = myFixture.getTempDirFixture().getFile("subfolder");
assert subfolder != null;
configuration.setWorkingDirectory(subfolder.getPath());
}
};
}
@Override
protected void checkTestResults(@NotNull final PyUnitTestProcessRunner runner,
@NotNull final String stdout,
@NotNull final String stderr,
@NotNull final String all) {
Assert.assertEquals("test failed: " + runner.getAllConsoleText(), 1, runner.getPassedTestsCount());
}
});
}
@Test
public void testDiff() {
runPythonTest(new PyUnitTestProcessWithConsoleTestTask("testRunner/env/unit/testDiff", "test_test.py") {
@@ -234,10 +264,10 @@ public final class PythonUnitTestingTest extends PythonUnitTestingLikeTest<PyUni
@NotNull final String all) {
assertEquals("Runner did not stop after first fail", 1, runner.getAllTestsCount());
assertEquals("Bad tree produced for failfast", "Test tree:\n" +
"[root]\n" +
".test_test\n" +
"..SomeTestCase\n" +
"...test_1_test(-)\n", runner.getFormattedTestTree());
"[root]\n" +
".test_test\n" +
"..SomeTestCase\n" +
"...test_1_test(-)\n", runner.getFormattedTestTree());
}
});
}
@@ -276,7 +306,7 @@ public final class PythonUnitTestingTest extends PythonUnitTestingLikeTest<PyUni
// Ensure failed and error subtests work
@Test
@StagingOn(os=TestEnv.WINDOWS) //Flaky
@StagingOn(os = TestEnv.WINDOWS) //Flaky
@EnvTestTagsRequired(tags = "python3")
public void testSubTestError() {
runPythonTest(new PyUnitTestProcessWithConsoleTestTask("testRunner/env/unit/subtestError", "test_test.py") {
@@ -307,7 +337,7 @@ public final class PythonUnitTestingTest extends PythonUnitTestingLikeTest<PyUni
// Ensure failed and error subtests work
@Test
@EnvTestTagsRequired(tags = "python3")
@StagingOn(os=TestEnv.WINDOWS) //Flaky
@StagingOn(os = TestEnv.WINDOWS) //Flaky
public void testSubTestAssertEqualsError() {
runPythonTest(new PyUnitTestProcessWithConsoleTestTask("testRunner/env/unit/subtestError", "test_assert_test.py") {
@@ -421,13 +451,13 @@ public final class PythonUnitTestingTest extends PythonUnitTestingLikeTest<PyUni
@NotNull final String stderr,
@NotNull final String all) {
assertEquals("Output tree broken for skipped exception thrown in setup method", "Test tree:\n" +
"[root]\n" +
".test_test\n" +
"..TestSimple\n" +
"...setUpClass(~)\n" +
"..TestSubSimple\n" +
"...setUpClass(~)\n",
runner.getFormattedTestTree());
"[root]\n" +
".test_test\n" +
"..TestSimple\n" +
"...setUpClass(~)\n" +
"..TestSubSimple\n" +
"...setUpClass(~)\n",
runner.getFormattedTestTree());
}
});
}
@@ -558,7 +588,7 @@ public final class PythonUnitTestingTest extends PythonUnitTestingLikeTest<PyUni
@EnvTestTagsRequired(tags = "python3") // No subtest in py2
@Test
@StagingOn(os=TestEnv.WINDOWS) //Flaky
@StagingOn(os = TestEnv.WINDOWS) //Flaky
public void testSubtest() {
runPythonTest(new PyUnitTestProcessWithConsoleTestTask("testRunner/env/unit/", "test_subtest.py", 1) {
@Override
@@ -588,7 +618,7 @@ public final class PythonUnitTestingTest extends PythonUnitTestingLikeTest<PyUni
}
@EnvTestTagsRequired(tags = "python3") // No subtest in py2
@StagingOn(os=TestEnv.WINDOWS) //Flaky
@StagingOn(os = TestEnv.WINDOWS) //Flaky
@Test
public void testSubtestSkipped() {
runPythonTest(new PyUnitTestProcessWithConsoleTestTask("testRunner/env/unit/", "test_skipped_subtest.py", 1) {
@@ -805,7 +835,7 @@ public final class PythonUnitTestingTest extends PythonUnitTestingLikeTest<PyUni
@NotNull final PsiElement elementToRightClickOn) {
super.checkConfiguration(configuration, elementToRightClickOn);
assertEquals("UnitTest does not obey default working directory", SOME_RANDOM_DIR,
configuration.getWorkingDirectorySafe());
configuration.getWorkingDirectorySafe());
}
}
);