From ed5616bed252d41d0d247c336f5b05a90962d2a7 Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Sun, 10 Jun 2018 12:42:36 +0100 Subject: [PATCH 1/8] add PyCharm debugging support --- .gitignore | 2 ++ pytest.ini | 2 -- runtests.py | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 04eb28083e1d..84ed3eea9b71 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ htmlcov # pytest cache .pytest_cache/ + +.tox diff --git a/pytest.ini b/pytest.ini index 808f581b639b..4b4094d1fe1f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -19,5 +19,3 @@ python_files = test*.py python_classes = python_functions = -# always run in parallel (requires pytest-xdist, see test-requirements.txt) -addopts = -nauto --cov-append --cov-report= diff --git a/runtests.py b/runtests.py index 31fc6d558b6f..f1da4b976f7e 100755 --- a/runtests.py +++ b/runtests.py @@ -83,10 +83,11 @@ def add_pytest(self, files: List[Tuple[str, str]], coverage: bool = True) -> Non if not pytest_files: return pytest_args = pytest_files + self.arglist + self.pyt_arglist + always_append = ['-n', 'auto', '--cov-append', ' --cov-report='] if coverage and self.coverage: - args = [sys.executable, '-m', 'pytest', '--cov=mypy'] + pytest_args + args = [sys.executable, '-m', 'pytest', '--cov=mypy'] + always_append + pytest_args else: - args = [sys.executable, '-m', 'pytest'] + pytest_args + args = [sys.executable, '-m', 'pytest', ] + always_append + pytest_args self.waiter.add(LazySubprocess('pytest', args, env=self.env, passthrough=self.verbosity), From 2bebcacea7c3bc19e6cead284a71f86ede0b4561 Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Thu, 7 Jun 2018 09:23:17 +0100 Subject: [PATCH 2/8] make sure tests pass running from within PyCharm --- mypy/test/testcmdline.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mypy/test/testcmdline.py b/mypy/test/testcmdline.py index 2a8b25687a75..57aad4a208e9 100644 --- a/mypy/test/testcmdline.py +++ b/mypy/test/testcmdline.py @@ -58,6 +58,14 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None: outb = process.stdout.read() # Split output into lines. out = [s.rstrip('\n\r') for s in str(outb, 'utf8').splitlines()] + + is_running_in_py_charm = "PYCHARM_HOSTED" in os.environ + if is_running_in_py_charm: + pos = next((p for p, i in enumerate(out) if i.startswith('pydev debugger: ')), None) + if pos is not None: + del out[pos] # the attaching debugger message itself + del out[pos] # plus the extra new line added + result = process.wait() # Remove temp file. os.remove(program_path) From 8ccac35fbae96320006fd53e2579071c9cb0df71 Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Sun, 10 Jun 2018 13:09:23 +0100 Subject: [PATCH 3/8] add tox configuration, and expose test runner via that --- .gitignore | 1 + runtests.py | 2 +- setup.cfg | 3 ++- tox.ini | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 84ed3eea9b71..066707713ba7 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ dmypy.json # Packages *.egg *.egg-info +*.eggs # IDEs .idea diff --git a/runtests.py b/runtests.py index f1da4b976f7e..9a27a18dab6a 100755 --- a/runtests.py +++ b/runtests.py @@ -83,7 +83,7 @@ def add_pytest(self, files: List[Tuple[str, str]], coverage: bool = True) -> Non if not pytest_files: return pytest_args = pytest_files + self.arglist + self.pyt_arglist - always_append = ['-n', 'auto', '--cov-append', ' --cov-report='] + always_append = ['-n', 'auto', '--cov-append', '--cov-report='] if coverage and self.coverage: args = [sys.executable, '-m', 'pytest', '--cov=mypy'] + always_append + pytest_args else: diff --git a/setup.cfg b/setup.cfg index cfc72fbd89a1..a853f2ac0ebf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,7 +25,8 @@ exclude = typeshed/*, # during runtests.py flake8 might be started when there's still examples in the temp dir tmp-test-dirs/* - + .tox + .eggs # Things to ignore: # E251: spaces around default arg value (against our style) diff --git a/tox.ini b/tox.ini new file mode 100644 index 000000000000..3283a7327262 --- /dev/null +++ b/tox.ini @@ -0,0 +1,40 @@ +[tox] +minversion = 2.9.1 +skip_missing_interpreters = true +envlist = py34, + py35, + py36, + py37, + lint, + type, + docs + +[testenv] +description = run the test driver with {basepython} +deps = -r ./test-requirements.txt +commands = python runtests.py -x lint -x package {posargs} + +[testenv:lint] +description = check the code style +basepython = python3.6 +commands = python runtests.py lint {posargs} + +[testenv:type] +description = type check ourselves +basepython = python3.6 +commands = python runtests.py testselfcheck -p '-n0' -p '-v' + +[testenv:docs] +description = invoke sphinx-build to build the HTML docs +basepython = python3.6 +deps = -r docs/requirements-docs.txt +commands = sphinx-build -d "{toxworkdir}/docs_doctree" docs/source "{toxworkdir}/docs_out" --color -W -bhtml {posargs} + +[testenv:dev] +description = generate a DEV environment, that has all project libraries +usedevelop = True +basepython = python3.6 +deps = -r ./test-requirements.txt + -r docs/requirements-docs.txt +commands = python -m pip list --format=columns + python -c 'import sys; print(sys.executable)' From ffc6436b9ee39c7b16bd494b7199a9d647b3fc9d Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Mon, 11 Jun 2018 11:04:25 +0100 Subject: [PATCH 4/8] Avoid having a space between requirement files in tox config as that breaks Windows --- tox.ini | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tox.ini b/tox.ini index 3283a7327262..6215f8711483 100644 --- a/tox.ini +++ b/tox.ini @@ -11,7 +11,7 @@ envlist = py34, [testenv] description = run the test driver with {basepython} -deps = -r ./test-requirements.txt +deps = -rtest-requirements.txt commands = python runtests.py -x lint -x package {posargs} [testenv:lint] @@ -27,14 +27,14 @@ commands = python runtests.py testselfcheck -p '-n0' -p '-v' [testenv:docs] description = invoke sphinx-build to build the HTML docs basepython = python3.6 -deps = -r docs/requirements-docs.txt +deps = -rdocs/requirements-docs.txt commands = sphinx-build -d "{toxworkdir}/docs_doctree" docs/source "{toxworkdir}/docs_out" --color -W -bhtml {posargs} [testenv:dev] description = generate a DEV environment, that has all project libraries usedevelop = True basepython = python3.6 -deps = -r ./test-requirements.txt - -r docs/requirements-docs.txt +deps = -rtest-requirements.txt + -rdocs/requirements-docs.txt commands = python -m pip list --format=columns python -c 'import sys; print(sys.executable)' From c3d2c28e1a4d3c8dbe4ac773ed4d8828da83d7c5 Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Mon, 11 Jun 2018 11:24:53 +0100 Subject: [PATCH 5/8] Avoid redundant local variable for PyCharm identification --- mypy/test/testcmdline.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mypy/test/testcmdline.py b/mypy/test/testcmdline.py index 57aad4a208e9..2eb944e135c9 100644 --- a/mypy/test/testcmdline.py +++ b/mypy/test/testcmdline.py @@ -59,8 +59,7 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None: # Split output into lines. out = [s.rstrip('\n\r') for s in str(outb, 'utf8').splitlines()] - is_running_in_py_charm = "PYCHARM_HOSTED" in os.environ - if is_running_in_py_charm: + if "PYCHARM_HOSTED" in os.environ: pos = next((p for p, i in enumerate(out) if i.startswith('pydev debugger: ')), None) if pos is not None: del out[pos] # the attaching debugger message itself From ea2914874c82243ac8d370f5fed407208d497374 Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Mon, 11 Jun 2018 11:26:24 +0100 Subject: [PATCH 6/8] Package suite moved to self-check --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 6215f8711483..b8865a0fc86f 100644 --- a/tox.ini +++ b/tox.ini @@ -12,7 +12,7 @@ envlist = py34, [testenv] description = run the test driver with {basepython} deps = -rtest-requirements.txt -commands = python runtests.py -x lint -x package {posargs} +commands = python runtests.py -x lint -x self-check {posargs} [testenv:lint] description = check the code style From f3d718d2974b2c7ef0e2bb9c55410c9e713e82fa Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Mon, 11 Jun 2018 11:27:04 +0100 Subject: [PATCH 7/8] For type tox environment use self-check package instead of the test file --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index b8865a0fc86f..91d636daf9ff 100644 --- a/tox.ini +++ b/tox.ini @@ -22,7 +22,7 @@ commands = python runtests.py lint {posargs} [testenv:type] description = type check ourselves basepython = python3.6 -commands = python runtests.py testselfcheck -p '-n0' -p '-v' +commands = python runtests.py self-check -p '-n0' -p '-v' [testenv:docs] description = invoke sphinx-build to build the HTML docs From e5567f4224bdf92469e9b5103432d6d462c6f311 Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Tue, 12 Jun 2018 12:49:36 +0100 Subject: [PATCH 8/8] restore pytest.ini parallel mode --- pytest.ini | 3 +++ runtests.py | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pytest.ini b/pytest.ini index 4b4094d1fe1f..621ac41315ed 100644 --- a/pytest.ini +++ b/pytest.ini @@ -19,3 +19,6 @@ python_files = test*.py python_classes = python_functions = +# always run in parallel (requires pytest-xdist, see test-requirements.txt) +addopts = -nauto + diff --git a/runtests.py b/runtests.py index 9a27a18dab6a..31fc6d558b6f 100755 --- a/runtests.py +++ b/runtests.py @@ -83,11 +83,10 @@ def add_pytest(self, files: List[Tuple[str, str]], coverage: bool = True) -> Non if not pytest_files: return pytest_args = pytest_files + self.arglist + self.pyt_arglist - always_append = ['-n', 'auto', '--cov-append', '--cov-report='] if coverage and self.coverage: - args = [sys.executable, '-m', 'pytest', '--cov=mypy'] + always_append + pytest_args + args = [sys.executable, '-m', 'pytest', '--cov=mypy'] + pytest_args else: - args = [sys.executable, '-m', 'pytest', ] + always_append + pytest_args + args = [sys.executable, '-m', 'pytest'] + pytest_args self.waiter.add(LazySubprocess('pytest', args, env=self.env, passthrough=self.verbosity),