Skip to content

Commit f2659f7

Browse files
authored
Merge master into features (#6458)
Merge master into features
2 parents 2d488f7 + b9c136b commit f2659f7

File tree

9 files changed

+134
-34
lines changed

9 files changed

+134
-34
lines changed

.github/workflows/main.yml

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# evaluating GitHub actions for CI, disconsider failures when evaluating PRs
1+
# evaluating GitHub actions for CI, disregard failures when evaluating PRs
22
#
33
# this is still missing:
44
# - deploy
5-
# - coverage
65
# - upload github notes
76
#
87
name: main
@@ -11,13 +10,14 @@ on:
1110
push:
1211
branches:
1312
- master
13+
- features
1414
pull_request:
1515
branches:
1616
- master
17+
- features
1718

1819
jobs:
1920
build:
20-
2121
runs-on: ${{ matrix.os }}
2222

2323
strategy:
@@ -86,6 +86,8 @@ jobs:
8686
python: "3.7"
8787
os: ubuntu-latest
8888
tox_env: "py37-freeze"
89+
# coverage does not apply for freeze test, skip it
90+
skip_coverage: true
8991
- name: "ubuntu-py38"
9092
python: "3.8"
9193
os: ubuntu-latest
@@ -94,6 +96,8 @@ jobs:
9496
python: "pypy3"
9597
os: ubuntu-latest
9698
tox_env: "pypy3-xdist"
99+
# coverage too slow with pypy3, skip it
100+
skip_coverage: true
97101

98102
- name: "macos-py37"
99103
python: "3.7"
@@ -118,6 +122,37 @@ jobs:
118122
- name: Install dependencies
119123
run: |
120124
python -m pip install --upgrade pip
121-
pip install tox
122-
- name: Test
123-
run: tox -e ${{ matrix.tox_env }}
125+
pip install tox coverage
126+
127+
- name: Test without coverage
128+
if: "matrix.skip_coverage"
129+
run: "tox -e ${{ matrix.tox_env }}"
130+
131+
- name: Test with coverage
132+
if: "! matrix.skip_coverage"
133+
env:
134+
_PYTEST_TOX_COVERAGE_RUN: "coverage run -m"
135+
COVERAGE_PROCESS_START: ".coveragerc"
136+
_PYTEST_TOX_EXTRA_DEP: "coverage-enable-subprocess"
137+
run: "tox -e ${{ matrix.tox_env }}"
138+
139+
- name: Prepare coverage token
140+
if: success() && !matrix.skip_coverage && ( github.repository == 'pytest-dev/pytest' || github.event_name == 'pull_request' )
141+
run: |
142+
python scripts/append_codecov_token.py
143+
144+
- name: Combine coverage
145+
if: success() && !matrix.skip_coverage
146+
run: |
147+
python -m coverage combine
148+
python -m coverage xml
149+
150+
- name: Codecov upload
151+
if: success() && !matrix.skip_coverage
152+
uses: codecov/codecov-action@v1
153+
with:
154+
token: ${{ secrets.codecov }}
155+
file: ./coverage.xml
156+
flags: ${{ runner.os }}
157+
fail_ci_if_error: false
158+
name: ${{ matrix.name }}

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ jobs:
5252
- env: TOXENV=pypy3-xdist
5353
python: 'pypy3'
5454

55-
- env: TOXENV=py35-xdist
56-
python: '3.5'
55+
# Coverage for Python 3.5.{0,1} specific code, mostly typing related.
56+
- env: TOXENV=py35 PYTEST_COVERAGE=1 PYTEST_ADDOPTS="-k test_raises_cyclic_reference"
57+
python: '3.5.1'
58+
dist: trusty
5759

5860
# Specialized factors for py37.
5961
- env: TOXENV=py37-pluggymaster-xdist

scripts/append_codecov_token.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Appends the codecov token to the 'codecov.yml' file at the root of the repository.
3+
4+
This is done by CI during PRs and builds on the pytest-dev repository so we can upload coverage, at least
5+
until codecov grows some native integration like it has with Travis and AppVeyor.
6+
7+
See discussion in https://github.com/pytest-dev/pytest/pull/6441 for more information.
8+
"""
9+
import os.path
10+
from textwrap import dedent
11+
12+
13+
def main():
14+
this_dir = os.path.dirname(__file__)
15+
cov_file = os.path.join(this_dir, "..", "codecov.yml")
16+
17+
assert os.path.isfile(cov_file), "{cov_file} does not exist".format(
18+
cov_file=cov_file
19+
)
20+
21+
with open(cov_file, "a") as f:
22+
# token from: https://codecov.io/gh/pytest-dev/pytest/settings
23+
# use same URL to regenerate it if needed
24+
text = dedent(
25+
"""
26+
codecov:
27+
token: "1eca3b1f-31a2-4fb8-a8c3-138b441b50a7"
28+
"""
29+
)
30+
f.write(text)
31+
32+
print("Token updated:", cov_file)
33+
34+
35+
if __name__ == "__main__":
36+
main()

src/_pytest/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def write(self, s) -> int:
382382
return self._other.write(s)
383383

384384

385-
if sys.version_info < (3, 5, 2): # pragma: no cover
385+
if sys.version_info < (3, 5, 2):
386386

387387
def overload(f): # noqa: F811
388388
return f

src/_pytest/config/findpaths.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def get_dir_from_path(path):
108108

109109

110110
def determine_setup(
111-
inifile: str,
111+
inifile: Optional[str],
112112
args: List[str],
113113
rootdir_cmd_arg: Optional[str] = None,
114114
config: Optional["Config"] = None,

testing/python/raises.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def __call__(self):
166166
# Early versions of Python 3.5 have some bug causing the
167167
# __call__ frame to still refer to t even after everything
168168
# is done. This makes the test pass for them.
169-
if sys.version_info < (3, 5, 2): # pragma: no cover
169+
if sys.version_info < (3, 5, 2):
170170
del self
171171
raise ValueError
172172

testing/test_config.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def test_simple_noini(self, tmpdir):
859859
assert get_common_ancestor([no_path.join("a")]) == tmpdir
860860

861861
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
862-
def test_with_ini(self, tmpdir, name):
862+
def test_with_ini(self, tmpdir, name) -> None:
863863
inifile = tmpdir.join(name)
864864
inifile.write("[pytest]\n" if name != "setup.cfg" else "[tool:pytest]\n")
865865

@@ -874,15 +874,15 @@ def test_with_ini(self, tmpdir, name):
874874
assert inifile == inifile
875875

876876
@pytest.mark.parametrize("name", "setup.cfg tox.ini".split())
877-
def test_pytestini_overrides_empty_other(self, tmpdir, name):
877+
def test_pytestini_overrides_empty_other(self, tmpdir, name) -> None:
878878
inifile = tmpdir.ensure("pytest.ini")
879879
a = tmpdir.mkdir("a")
880880
a.ensure(name)
881881
rootdir, inifile, inicfg = determine_setup(None, [a])
882882
assert rootdir == tmpdir
883883
assert inifile == inifile
884884

885-
def test_setuppy_fallback(self, tmpdir):
885+
def test_setuppy_fallback(self, tmpdir) -> None:
886886
a = tmpdir.mkdir("a")
887887
a.ensure("setup.cfg")
888888
tmpdir.ensure("setup.py")
@@ -891,14 +891,14 @@ def test_setuppy_fallback(self, tmpdir):
891891
assert inifile is None
892892
assert inicfg == {}
893893

894-
def test_nothing(self, tmpdir, monkeypatch):
894+
def test_nothing(self, tmpdir, monkeypatch) -> None:
895895
monkeypatch.chdir(str(tmpdir))
896896
rootdir, inifile, inicfg = determine_setup(None, [tmpdir])
897897
assert rootdir == tmpdir
898898
assert inifile is None
899899
assert inicfg == {}
900900

901-
def test_with_specific_inifile(self, tmpdir):
901+
def test_with_specific_inifile(self, tmpdir) -> None:
902902
inifile = tmpdir.ensure("pytest.ini")
903903
rootdir, inifile, inicfg = determine_setup(inifile, [tmpdir])
904904
assert rootdir == tmpdir
@@ -1039,15 +1039,15 @@ def test():
10391039
result = testdir.runpytest("--override-ini", "python_files=unittest_*.py")
10401040
result.stdout.fnmatch_lines(["*1 passed in*"])
10411041

1042-
def test_with_arg_outside_cwd_without_inifile(self, tmpdir, monkeypatch):
1042+
def test_with_arg_outside_cwd_without_inifile(self, tmpdir, monkeypatch) -> None:
10431043
monkeypatch.chdir(str(tmpdir))
10441044
a = tmpdir.mkdir("a")
10451045
b = tmpdir.mkdir("b")
10461046
rootdir, inifile, inicfg = determine_setup(None, [a, b])
10471047
assert rootdir == tmpdir
10481048
assert inifile is None
10491049

1050-
def test_with_arg_outside_cwd_with_inifile(self, tmpdir):
1050+
def test_with_arg_outside_cwd_with_inifile(self, tmpdir) -> None:
10511051
a = tmpdir.mkdir("a")
10521052
b = tmpdir.mkdir("b")
10531053
inifile = a.ensure("pytest.ini")
@@ -1056,13 +1056,13 @@ def test_with_arg_outside_cwd_with_inifile(self, tmpdir):
10561056
assert inifile == parsed_inifile
10571057

10581058
@pytest.mark.parametrize("dirs", ([], ["does-not-exist"], ["a/does-not-exist"]))
1059-
def test_with_non_dir_arg(self, dirs, tmpdir):
1059+
def test_with_non_dir_arg(self, dirs, tmpdir) -> None:
10601060
with tmpdir.ensure(dir=True).as_cwd():
10611061
rootdir, inifile, inicfg = determine_setup(None, dirs)
10621062
assert rootdir == tmpdir
10631063
assert inifile is None
10641064

1065-
def test_with_existing_file_in_subdir(self, tmpdir):
1065+
def test_with_existing_file_in_subdir(self, tmpdir) -> None:
10661066
a = tmpdir.mkdir("a")
10671067
a.ensure("exist")
10681068
with tmpdir.as_cwd():

testing/test_reports.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
import pytest
24
from _pytest._code.code import ExceptionChainRepr
35
from _pytest.pathlib import Path
@@ -314,27 +316,52 @@ def check_longrepr(longrepr):
314316
# elsewhere and we do check the contents of the longrepr object after loading it.
315317
loaded_report.longrepr.toterminal(tw_mock)
316318

317-
def test_chained_exceptions_no_reprcrash(
318-
self, testdir, tw_mock,
319-
):
319+
def test_chained_exceptions_no_reprcrash(self, testdir, tw_mock):
320320
"""Regression test for tracebacks without a reprcrash (#5971)
321321
322322
This happens notably on exceptions raised by multiprocess.pool: the exception transfer
323323
from subprocess to main process creates an artificial exception, which ExceptionInfo
324324
can't obtain the ReprFileLocation from.
325325
"""
326-
testdir.makepyfile(
326+
# somehow in Python 3.5 on Windows this test fails with:
327+
# File "c:\...\3.5.4\x64\Lib\multiprocessing\connection.py", line 302, in _recv_bytes
328+
# overlapped=True)
329+
# OSError: [WinError 6] The handle is invalid
330+
#
331+
# so in this platform we opted to use a mock traceback which is identical to the
332+
# one produced by the multiprocessing module
333+
if sys.version_info[:2] <= (3, 5) and sys.platform.startswith("win"):
334+
testdir.makepyfile(
335+
"""
336+
# equivalent of multiprocessing.pool.RemoteTraceback
337+
class RemoteTraceback(Exception):
338+
def __init__(self, tb):
339+
self.tb = tb
340+
def __str__(self):
341+
return self.tb
342+
def test_a():
343+
try:
344+
raise ValueError('value error')
345+
except ValueError as e:
346+
# equivalent to how multiprocessing.pool.rebuild_exc does it
347+
e.__cause__ = RemoteTraceback('runtime error')
348+
raise e
327349
"""
328-
from concurrent.futures import ProcessPoolExecutor
350+
)
351+
else:
352+
testdir.makepyfile(
353+
"""
354+
from concurrent.futures import ProcessPoolExecutor
329355
330-
def func():
331-
raise ValueError('value error')
356+
def func():
357+
raise ValueError('value error')
358+
359+
def test_a():
360+
with ProcessPoolExecutor() as p:
361+
p.submit(func).result()
362+
"""
363+
)
332364

333-
def test_a():
334-
with ProcessPoolExecutor() as p:
335-
p.submit(func).result()
336-
"""
337-
)
338365
reprec = testdir.inline_run()
339366

340367
reports = reprec.getreports("pytest_runtest_logreport")

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ passenv = USER USERNAME COVERAGE_* TRAVIS PYTEST_ADDOPTS TERM
2626
setenv =
2727
_PYTEST_TOX_DEFAULT_POSARGS={env:_PYTEST_TOX_POSARGS_LSOF:} {env:_PYTEST_TOX_POSARGS_XDIST:}
2828

29-
# Configuration to run with coverage similar to Travis/Appveyor, e.g.
29+
# Configuration to run with coverage similar to CI, e.g.
3030
# "tox -e py37-coverage".
3131
coverage: _PYTEST_TOX_COVERAGE_RUN=coverage run -m
3232
coverage: _PYTEST_TOX_EXTRA_DEP=coverage-enable-subprocess
@@ -53,7 +53,7 @@ deps =
5353
skip_install = True
5454
basepython = python3
5555
deps = pre-commit>=1.11.0
56-
commands = pre-commit run --all-files --show-diff-on-failure
56+
commands = pre-commit run --all-files --show-diff-on-failure {posargs:}
5757

5858
[testenv:docs]
5959
basepython = python3

0 commit comments

Comments
 (0)