From e7d1ad69b9e52569ceb7f97b54ebf97361d7b210 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Wed, 18 Sep 2024 19:07:12 +0200 Subject: [PATCH] Individual coverage: skip logic-free __init__ files (#7186) individual coverage: skip logic-free __init__ files --- pyproject.toml | 9 +-------- test/individual_coverage.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bbbe6f454..37e5f8514 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -136,6 +136,7 @@ exclude_lines = [ [tool.pytest.ini_options] asyncio_mode = "auto" +asyncio_default_fixture_loop_scope = "function" testpaths = "test" addopts = "--capture=no --color=yes" filterwarnings = [ @@ -155,19 +156,16 @@ exclude = [ "mitmproxy/contentviews/__init__.py", "mitmproxy/contentviews/base.py", "mitmproxy/contentviews/grpc.py", - "mitmproxy/contentviews/image/__init__.py", "mitmproxy/contrib/*", "mitmproxy/ctx.py", "mitmproxy/exceptions.py", "mitmproxy/flow.py", - "mitmproxy/io/__init__.py", "mitmproxy/io/io.py", "mitmproxy/io/tnetstring.py", "mitmproxy/log.py", "mitmproxy/master.py", "mitmproxy/net/check.py", "mitmproxy/net/http/cookies.py", - "mitmproxy/net/http/http1/__init__.py", "mitmproxy/net/http/multipart.py", "mitmproxy/net/tls.py", "mitmproxy/platform/__init__.py", @@ -177,7 +175,6 @@ exclude = [ "mitmproxy/platform/pf.py", "mitmproxy/platform/windows.py", "mitmproxy/proxy/__init__.py", - "mitmproxy/proxy/layers/__init__.py", "mitmproxy/proxy/layers/http/__init__.py", "mitmproxy/proxy/layers/http/_base.py", "mitmproxy/proxy/layers/http/_events.py", @@ -190,11 +187,9 @@ exclude = [ "mitmproxy/proxy/layers/http/_upstream_proxy.py", "mitmproxy/proxy/layers/tls.py", "mitmproxy/proxy/server.py", - "mitmproxy/script/__init__.py", "mitmproxy/test/taddons.py", "mitmproxy/test/tflow.py", "mitmproxy/test/tutils.py", - "mitmproxy/tools/console/__init__.py", "mitmproxy/tools/console/commander/commander.py", "mitmproxy/tools/console/commandexecutor.py", "mitmproxy/tools/console/commands.py", @@ -204,7 +199,6 @@ exclude = [ "mitmproxy/tools/console/flowdetailview.py", "mitmproxy/tools/console/flowlist.py", "mitmproxy/tools/console/flowview.py", - "mitmproxy/tools/console/grideditor/__init__.py", "mitmproxy/tools/console/grideditor/base.py", "mitmproxy/tools/console/grideditor/col_bytes.py", "mitmproxy/tools/console/grideditor/col_subgrid.py", @@ -225,7 +219,6 @@ exclude = [ "mitmproxy/tools/console/tabs.py", "mitmproxy/tools/console/window.py", "mitmproxy/tools/main.py", - "mitmproxy/tools/web/__init__.py", "mitmproxy/tools/web/app.py", "mitmproxy/tools/web/master.py", "mitmproxy/tools/web/webaddons.py", diff --git a/test/individual_coverage.py b/test/individual_coverage.py index cd992f2fb..1d6648ca6 100755 --- a/test/individual_coverage.py +++ b/test/individual_coverage.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import ast import asyncio import fnmatch import os @@ -27,6 +28,20 @@ async def main(): async def run_tests(f: Path, should_fail: bool) -> None: if f.name == "__init__.py": + mod = ast.parse(f.read_text()) + full_cov_on_import = all( + isinstance(stmt, (ast.ImportFrom, ast.Import, ast.Assign)) + for stmt in mod.body + ) + if full_cov_on_import: + if should_fail: + raise RuntimeError( + f"Remove {f} from tool.pytest.individual_coverage in pyproject.toml." + ) + else: + print(f"{f}: skip __init__.py file without logic") + return + test_file = Path("test") / f.parent.with_name(f"test_{f.parent.name}.py") else: test_file = Path("test") / f.with_name(f"test_{f.name}")