From 7dfbecd3924a0d7a9e555e9cc3618cdb06b5415d Mon Sep 17 00:00:00 2001 From: Andrey Rakhmatullin Date: Tue, 7 Jan 2025 19:11:10 +0500 Subject: [PATCH 1/2] Fix tracking of coverage in subprocesses. --- pyproject.toml | 6 ++++++ tests/__init__.py | 7 ------- tox.ini | 10 +++++----- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 571a61f1c..29e26399f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -120,6 +120,12 @@ include = ["scrapy/*"] omit = ["tests/*"] disable_warnings = ["include-ignored"] +[tool.coverage.paths] +source = [ + "scrapy", + ".tox/**/site-packages/scrapy" +] + [tool.coverage.report] # https://github.com/nedbat/coveragepy/issues/831#issuecomment-517778185 exclude_lines = ["pragma: no cover", "if TYPE_CHECKING:"] diff --git a/tests/__init__.py b/tests/__init__.py index 5f0c0f7ad..cd52ade58 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -15,13 +15,6 @@ os.environ["http_proxy"] = "" os.environ["https_proxy"] = "" os.environ["ftp_proxy"] = "" -# Absolutize paths to coverage config and output file because tests that -# spawn subprocesses also changes current working directory. -_sourceroot = Path(__file__).resolve().parent.parent -if "COV_CORE_CONFIG" in os.environ: - os.environ["COVERAGE_FILE"] = str(_sourceroot / ".coverage") - os.environ["COV_CORE_CONFIG"] = str(_sourceroot / os.environ["COV_CORE_CONFIG"]) - tests_datadir = str(Path(__file__).parent.resolve() / "sample_data") diff --git a/tox.ini b/tox.ini index 39ab1ccd4..de91c8b04 100644 --- a/tox.ini +++ b/tox.ini @@ -14,7 +14,7 @@ deps = pyftpdlib >= 2.0.1 pygments pytest - pytest-cov==4.0.0 + pytest-cov >= 4.0.0 pytest-xdist sybil >= 1.3.0 # https://github.com/cjw296/sybil/issues/20#issuecomment-605433422 testfixtures @@ -36,7 +36,7 @@ passenv = #allow tox virtualenv to upgrade pip/wheel/setuptools download = true commands = - pytest --cov=scrapy --cov-report=xml --cov-report= {posargs:--durations=10 docs scrapy tests} --doctest-modules + pytest --cov-config=pyproject.toml --cov=scrapy --cov-report=xml --cov-report= {posargs:--durations=10 docs scrapy tests} --doctest-modules install_command = python -I -m pip install -ctests/upper-constraints.txt {opts} {packages} @@ -115,7 +115,7 @@ setenv = install_command = python -I -m pip install {opts} {packages} commands = - pytest --cov=scrapy --cov-report=xml --cov-report= {posargs:--durations=10 scrapy tests} + pytest --cov-config=pyproject.toml --cov=scrapy --cov-report=xml --cov-report= {posargs:--durations=10 scrapy tests} [testenv:pinned] basepython = {[pinned]basepython} @@ -241,7 +241,7 @@ deps = {[testenv]deps} botocore>=1.4.87 commands = - pytest --cov=scrapy --cov-report=xml --cov-report= {posargs:tests -m requires_botocore} + pytest --cov-config=pyproject.toml --cov=scrapy --cov-report=xml --cov-report= {posargs:tests -m requires_botocore} [testenv:botocore-pinned] basepython = {[pinned]basepython} @@ -252,4 +252,4 @@ install_command = {[pinned]install_command} setenv = {[pinned]setenv} commands = - pytest --cov=scrapy --cov-report=xml --cov-report= {posargs:tests -m requires_botocore} + pytest --cov-config=pyproject.toml --cov=scrapy --cov-report=xml --cov-report= {posargs:tests -m requires_botocore} From 3154b08e90d9777dfe2879b8686b6fc63a793c84 Mon Sep 17 00:00:00 2001 From: Andrey Rakhmatullin Date: Tue, 7 Jan 2025 19:40:25 +0500 Subject: [PATCH 2/2] Improve coverage speed on Python 3.12+. --- tox.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tox.ini b/tox.ini index de91c8b04..cf5e19a61 100644 --- a/tox.ini +++ b/tox.ini @@ -10,6 +10,7 @@ minversion = 1.7.0 [test-requirements] deps = attrs + coverage >= 7.4.0 pexpect >= 4.8.0 pyftpdlib >= 2.0.1 pygments @@ -26,6 +27,8 @@ deps = # mitmproxy does not support PyPy mitmproxy; implementation_name != 'pypy' +setenv = + COVERAGE_CORE=sysmon passenv = S3_TEST_FILE_URI AWS_ACCESS_KEY_ID