--- /dev/null
+import re
+import subprocess as sp
+
+import pytest
+
+
+def pytest_collection_modifyitems(items):
+ # All the tests using mypy are slow
+ for item in items:
+ if "mypy" in item.fixturenames:
+ item.add_marker(pytest.mark.slow)
+
+
+@pytest.fixture(scope="session")
+def mypy(tmp_path_factory):
+ cache_dir = tmp_path_factory.mktemp(basename="mypy_cache")
+ src_dir = tmp_path_factory.mktemp("source")
+
+ class MypyRunner:
+ def run_on_file(self, filename):
+ cmdline = f"""
+ mypy
+ --strict
+ --show-error-codes --no-color-output --no-error-summary
+ --config-file= --cache-dir={cache_dir}
+ """.split()
+ cmdline.append(filename)
+ return sp.run(cmdline, stdout=sp.PIPE, stderr=sp.STDOUT)
+
+ def run_on_source(self, source):
+ fn = src_dir / "tmp.py"
+ with fn.open("w") as f:
+ f.write(source)
+
+ return self.run_on_file(str(fn))
+
+ def get_revealed(self, line):
+ """return the type from an output of reveal_type"""
+ return re.sub(
+ r".*Revealed type is (['\"])([^']+)\1.*", r"\2", line
+ ).replace("*", "")
+
+ return MypyRunner()
-import re
import sys
-import subprocess as sp
import pytest
-@pytest.mark.slow
@pytest.mark.parametrize(
"filename",
[
assert cp.returncode == 0
-@pytest.mark.slow
@pytest.mark.parametrize(
"conn, type",
[
_test_reveal(stmts, type, mypy)
-@pytest.mark.slow
@pytest.mark.parametrize(
"conn, curs, type",
[
_test_reveal(stmts, type, mypy)
-@pytest.mark.slow
@pytest.mark.parametrize(
"curs, type",
[
_test_reveal(stmts, type, mypy)
-@pytest.mark.slow
@pytest.mark.parametrize(
"curs, type",
[
_test_reveal(stmts, type, mypy)
-@pytest.mark.slow
@pytest.mark.parametrize("method", ["fetchmany", "fetchall"])
@pytest.mark.parametrize(
"curs, type",
_test_reveal(stmts, type, mypy)
-@pytest.mark.slow
@pytest.mark.parametrize("server_side", [False, True])
@pytest.mark.parametrize("conn_class", ["Connection", "AsyncConnection"])
def test_cur_subclass_execute(mypy, conn_class, server_side):
assert types[0] == types[2]
-@pytest.fixture(scope="session")
-def mypy(tmp_path_factory):
- cache_dir = tmp_path_factory.mktemp(basename="mypy_cache")
- src_dir = tmp_path_factory.mktemp("source")
-
- class MypyRunner:
- def run_on_file(self, filename):
- cmdline = f"""
- mypy
- --strict
- --show-error-codes --no-color-output --no-error-summary
- --config-file= --cache-dir={cache_dir}
- """.split()
- cmdline.append(filename)
- return sp.run(cmdline, stdout=sp.PIPE, stderr=sp.STDOUT)
-
- def run_on_source(self, source):
- fn = src_dir / "tmp.py"
- with fn.open("w") as f:
- f.write(source)
-
- return self.run_on_file(str(fn))
-
- def get_revealed(self, line):
- """return the type from an output of reveal_type"""
- return re.sub(
- r".*Revealed type is (['\"])([^']+)\1.*", r"\2", line
- ).replace("*", "")
-
- return MypyRunner()
-
-
def _test_reveal(stmts, type, mypy):
ignore = (
"" if type.startswith("Optional") else "# type: ignore[assignment]"