diff --git a/python/helpers/pycharm/_jb_tox_runner.py b/python/helpers/pycharm/_jb_tox_runner.py index 0009cbfffcb5..7288efa21afd 100644 --- a/python/helpers/pycharm/_jb_tox_runner.py +++ b/python/helpers/pycharm/_jb_tox_runner.py @@ -106,7 +106,7 @@ class _Nose(object): _RUNNERS = [_Unit2(), _PyTest(), _Nose()] import sys -config = tox_config.parseconfig(args=sys.argv) +config = tox_config.parseconfig(args=sys.argv[1:]) for env, tmp_config in config.envconfigs.items(): if not tmp_config.setenv: tmp_config.setenv = dict() diff --git a/python/testData/toxtest/toxPosArgs/spam.py b/python/testData/toxtest/toxPosArgs/spam.py new file mode 100644 index 000000000000..ba23f69d17c1 --- /dev/null +++ b/python/testData/toxtest/toxPosArgs/spam.py @@ -0,0 +1,2 @@ +import sys +print(sys.argv) \ No newline at end of file diff --git a/python/testData/toxtest/toxPosArgs/tox.ini b/python/testData/toxtest/toxPosArgs/tox.ini new file mode 100644 index 000000000000..27ca25bb5250 --- /dev/null +++ b/python/testData/toxtest/toxPosArgs/tox.ini @@ -0,0 +1,5 @@ +[tox] +skipsdist=True +envlist = py27 +[testenv] +commands=python spam.py {posargs} \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/env/PyToxTest.java b/python/testSrc/com/jetbrains/env/PyToxTest.java index 66654c83f7bc..ab90719fe940 100644 --- a/python/testSrc/com/jetbrains/env/PyToxTest.java +++ b/python/testSrc/com/jetbrains/env/PyToxTest.java @@ -12,6 +12,7 @@ import com.jetbrains.python.testing.tox.PyToxConfigurationFactory; import com.jetbrains.python.testing.tox.PyToxTestTools; import com.jetbrains.python.tools.sdkTools.SdkCreationType; import org.assertj.core.api.Condition; +import org.hamcrest.Matchers; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.junit.Assert; @@ -158,6 +159,44 @@ public final class PyToxTest extends PyEnvTestCase { ); } + + /** + * Ensures {posargs} are passed correctly + */ + @Test + public void testToxPosArgs() { + runPythonTest( + new PyProcessWithConsoleTestTask>("/toxtest/toxPosArgs/", SdkCreationType.EMPTY_SDK) { + + @NotNull + @Override + protected PyAbstractTestProcessRunner createProcessRunner() { + return new MyTestProcessRunner() { + @Override + protected void configurationCreatedAndWillLaunch(@NotNull final PyToxConfiguration configuration) throws IOException { + super.configurationCreatedAndWillLaunch(configuration); + PyToxTestTools.setArguments(configuration, "arg1"); + } + }; + } + + + @Override + protected void checkTestResults(@NotNull final PyAbstractTestProcessRunner runner, + @NotNull final String stdout, + @NotNull final String stderr, + @NotNull final String all) { + Assert.assertThat("Wrong sys.argv", stdout, Matchers.containsString("['spam.py', 'arg1']")); + } + + @NotNull + @Override + public Set getTags() { + return Sets.newHashSet("tox"); + } + }); + } + /** * Provide certain env and check it is launched */ @@ -364,7 +403,7 @@ public final class PyToxTest extends PyEnvTestCase { } } - private static final class MyTestProcessRunner extends PyAbstractTestProcessRunner { + private static class MyTestProcessRunner extends PyAbstractTestProcessRunner { private MyTestProcessRunner() { this(0); }