Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Pytest configuration #11577

Merged
merged 9 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ Bugs fixed
Testing
-------

* #11577: pytest: Fail tests on "XPASS".
* #11577: pytest: Use "importlib" import mode.
* #11577: pytest: Set PYTHONWARNINGS=error.
* #11577: pytest: Set strict config and strict markers.

Release 7.1.2 (released Aug 02, 2023)
=====================================

Expand Down
14 changes: 12 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ lint = [
test = [
"pytest>=4.6",
"html5lib",
"cython",
"filelock"
"cython>=3.0",
"setuptools>=67.0", # for Cython compilation
"filelock",
]

[[project.authors]]
Expand Down Expand Up @@ -346,6 +347,14 @@ module = [
disallow_any_generics = false

[tool.pytest.ini_options]
minversion = 4.6
addopts = [
"--import-mode=importlib",
"--pythonwarnings=error",
"--strict-config",
"--strict-markers",
]
empty_parameter_set_mark = "xfail"
filterwarnings = [
"all",
"ignore::DeprecationWarning:docutils.io",
Expand All @@ -356,6 +365,7 @@ markers = [
"apidoc",
]
testpaths = ["tests"]
xfail_strict = true

[tool.coverage.run]
branch = true
Expand Down
10 changes: 5 additions & 5 deletions sphinx/pycode/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_lvar_names(node: ast.AST, self: ast.arg | None = None) -> list[str]:
self_id = self.arg

node_name = node.__class__.__name__
if node_name in ('Index', 'Num', 'Slice', 'Str', 'Subscript'):
if node_name in ('Constant', 'Index', 'Slice', 'Subscript'):
raise TypeError('%r does not create new variable' % node)
if node_name == 'Name':
if self is None or node.id == self_id: # type: ignore
Expand Down Expand Up @@ -403,15 +403,15 @@ def visit_AnnAssign(self, node: ast.AnnAssign) -> None:
def visit_Expr(self, node: ast.Expr) -> None:
"""Handles Expr node and pick up a comment if string."""
if (isinstance(self.previous, (ast.Assign, ast.AnnAssign)) and
isinstance(node.value, ast.Str)):
isinstance(node.value, ast.Constant) and isinstance(node.value.value, str)):
try:
targets = get_assign_targets(self.previous)
varnames = get_lvar_names(targets[0], self.get_self())
for varname in varnames:
if isinstance(node.value.s, str):
docstring = node.value.s
if isinstance(node.value.value, str):
docstring = node.value.value
else:
docstring = node.value.s.decode(self.encoding or 'utf-8')
docstring = node.value.value.decode(self.encoding or 'utf-8')

self.add_variable_comment(varname, dedent_docstring(docstring))
self.add_entry(varname)
Expand Down
18 changes: 13 additions & 5 deletions sphinx/testing/restructuredtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ def parse(app: Sphinx, text: str, docname: str = 'index') -> nodes.document:
parser = RSTParser()
parser.set_application(app)
with sphinx_domains(app.env):
return publish_doctree(text, path.join(app.srcdir, docname + '.rst'),
reader=reader,
parser=parser,
settings_overrides={'env': app.env,
'gettext_compact': True})
return publish_doctree(
text,
path.join(app.srcdir, docname + '.rst'),
reader=reader,
parser=parser,
settings_overrides={
'env': app.env,
'gettext_compact': True,
'input_encoding': 'utf-8',
'output_encoding': 'unicode',
'traceback': True,
},
)
finally:
app.env.temp_data.pop('docname', None)
2 changes: 1 addition & 1 deletion sphinx/testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(

self.docutils_conf_path = srcdir / 'docutils.conf'
if docutilsconf is not None:
self.docutils_conf_path.write_text(docutilsconf)
self.docutils_conf_path.write_text(docutilsconf, encoding='utf8')

if builddir is None:
builddir = srcdir / '_build'
Expand Down
2 changes: 0 additions & 2 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import os
import shutil
import sys
from unittest import mock

import pytest
Expand Down Expand Up @@ -50,7 +49,6 @@ def nonascii_srcdir(request, rootdir, sphinx_test_tempdir):
)
@mock.patch('sphinx.builders.linkcheck.requests.head',
side_effect=request_session_head)
@pytest.mark.xfail(sys.platform == 'win32', reason="Not working on windows")
def test_build_all(requests_head, make_app, nonascii_srcdir, buildername):
app = make_app(buildername, srcdir=nonascii_srcdir)
app.build()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def source_date_year(request, monkeypatch):
sde = request.param
with monkeypatch.context() as m:
if sde:
m.setenv('SOURCE_DATE_EPOCH', sde)
m.setenv('SOURCE_DATE_EPOCH', str(sde))
yield time.gmtime(sde).tm_year
else:
m.delenv('SOURCE_DATE_EPOCH', raising=False)
Expand Down
25 changes: 3 additions & 22 deletions tests/test_directive_code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test the code-block directive."""

import os
import os.path

import pytest
from docutils import nodes
Expand All @@ -23,7 +23,6 @@ def literal_inc_path(testroot):
return testroot / 'literal.inc'


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader(literal_inc_path):
options = {'lineno-match': True}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -33,7 +32,6 @@ def test_LiteralIncludeReader(literal_inc_path):
assert reader.lineno_start == 1


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_lineno_start(literal_inc_path):
options = {'lineno-start': 4}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -43,7 +41,6 @@ def test_LiteralIncludeReader_lineno_start(literal_inc_path):
assert reader.lineno_start == 4


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_pyobject1(literal_inc_path):
options = {'lineno-match': True, 'pyobject': 'Foo'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -53,7 +50,6 @@ def test_LiteralIncludeReader_pyobject1(literal_inc_path):
assert reader.lineno_start == 5


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_pyobject2(literal_inc_path):
options = {'pyobject': 'Bar'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -64,7 +60,6 @@ def test_LiteralIncludeReader_pyobject2(literal_inc_path):
assert reader.lineno_start == 1 # no lineno-match


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_pyobject3(literal_inc_path):
options = {'pyobject': 'Bar.baz'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -73,7 +68,6 @@ def test_LiteralIncludeReader_pyobject3(literal_inc_path):
" pass\n")


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_pyobject_and_lines(literal_inc_path):
options = {'pyobject': 'Bar', 'lines': '2-'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -82,7 +76,6 @@ def test_LiteralIncludeReader_pyobject_and_lines(literal_inc_path):
" pass\n")


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_lines1(literal_inc_path):
options = {'lines': '1-3'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -92,7 +85,6 @@ def test_LiteralIncludeReader_lines1(literal_inc_path):
"foo = \"Including Unicode characters: üöä\"\n")


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_lines2(literal_inc_path):
options = {'lines': '1,3,5'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -102,7 +94,6 @@ def test_LiteralIncludeReader_lines2(literal_inc_path):
"class Foo:\n")


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_lines_and_lineno_match1(literal_inc_path):
options = {'lines': '3-5', 'lineno-match': True}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -129,7 +120,6 @@ def test_LiteralIncludeReader_lines_and_lineno_match3(literal_inc_path, app, sta
reader.read()


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_start_at(literal_inc_path):
options = {'lineno-match': True, 'start-at': 'Foo', 'end-at': 'Bar'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -141,7 +131,6 @@ def test_LiteralIncludeReader_start_at(literal_inc_path):
assert reader.lineno_start == 5


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_start_after(literal_inc_path):
options = {'lineno-match': True, 'start-after': 'Foo', 'end-before': 'Bar'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -151,7 +140,6 @@ def test_LiteralIncludeReader_start_after(literal_inc_path):
assert reader.lineno_start == 6


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_start_after_and_lines(literal_inc_path):
options = {'lineno-match': True, 'lines': '6-',
'start-after': 'Literally', 'end-before': 'comment'}
Expand All @@ -165,7 +153,6 @@ def test_LiteralIncludeReader_start_after_and_lines(literal_inc_path):
assert reader.lineno_start == 7


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_start_at_and_lines(literal_inc_path):
options = {'lines': '2, 3, 5', 'start-at': 'foo', 'end-before': '#'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand Down Expand Up @@ -206,7 +193,6 @@ def test_LiteralIncludeReader_end_before(literal_inc_path):
"\n")


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_prepend(literal_inc_path):
options = {'lines': '1', 'prepend': 'Hello', 'append': 'Sphinx'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -216,7 +202,6 @@ def test_LiteralIncludeReader_prepend(literal_inc_path):
"Sphinx\n")


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_dedent(literal_inc_path):
# dedent: 2
options = {'lines': '9-11', 'dedent': 2}
Expand Down Expand Up @@ -251,7 +236,6 @@ def test_LiteralIncludeReader_dedent(literal_inc_path):
"\n")


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_dedent_and_append_and_prepend(literal_inc_path):
# dedent: 2
options = {'lines': '9-11', 'dedent': 2, 'prepend': 'class Foo:', 'append': '# comment'}
Expand All @@ -264,7 +248,6 @@ def test_LiteralIncludeReader_dedent_and_append_and_prepend(literal_inc_path):
"# comment\n")


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_tabwidth(testroot):
# tab-width: 4
options = {'tab-width': 4, 'pyobject': 'Qux'}
Expand All @@ -283,7 +266,6 @@ def test_LiteralIncludeReader_tabwidth(testroot):
" pass\n")


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_tabwidth_dedent(testroot):
options = {'tab-width': 4, 'dedent': 4, 'pyobject': 'Qux.quux'}
reader = LiteralIncludeReader(testroot / 'target.py', options, DUMMY_CONFIG)
Expand All @@ -292,13 +274,12 @@ def test_LiteralIncludeReader_tabwidth_dedent(testroot):
" pass\n")


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_LiteralIncludeReader_diff(testroot, literal_inc_path):
options = {'diff': testroot / 'literal-diff.inc'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("--- " + str(testroot) + "/literal-diff.inc\n"
"+++ " + str(testroot) + "/literal.inc\n"
assert content == ("--- " + os.path.join(testroot, 'literal-diff.inc') + "\n"
"+++ " + os.path.join(testroot, 'literal.inc') + "\n"
"@@ -6,8 +6,8 @@\n"
" pass\n"
" \n"
Expand Down
1 change: 0 additions & 1 deletion tests/test_ext_intersphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ def assert_(rn, expected):
case(term=False, doc=False, py=False)


@pytest.mark.xfail(os.name != 'posix', reason="Path separator mismatch issue")
def test_inventory_not_having_version(tmp_path, app, status, warning):
inv_file = tmp_path / 'inventory'
inv_file.write_bytes(inventory_v2_not_having_version)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_intl.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def test_text_warning_node(app):
@sphinx_intl
@pytest.mark.sphinx('text')
@pytest.mark.test_params(shared_result='test_intl_basic')
@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_text_title_underline(app):
app.build()
# --- simple translation; check title underlines
Expand Down Expand Up @@ -1352,7 +1351,6 @@ def test_text_prolog_epilog_substitution(app):
srcdir='test_intl_images',
confoverrides={'language': 'xx'},
)
@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_image_glob_intl(app):
app.build()

Expand Down Expand Up @@ -1399,7 +1397,6 @@ def test_image_glob_intl(app):
'figure_language_filename': '{root}{ext}.{language}',
},
)
@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
def test_image_glob_intl_using_figure_language_filename(app):
app.build()

Expand Down
6 changes: 3 additions & 3 deletions tests/test_util_fileutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_copy_asset_file(tmp_path):

# copy normal file
src = (tmp_path / 'asset.txt')
src.write_text('# test data')
src.write_text('# test data', encoding='utf8')
dest = (tmp_path / 'output.txt')

copy_asset_file(src, dest)
Expand All @@ -29,7 +29,7 @@ def test_copy_asset_file(tmp_path):

# copy template file
src = (tmp_path / 'asset.txt_t')
src.write_text('# {{var1}} data')
src.write_text('# {{var1}} data', encoding='utf8')
dest = (tmp_path / 'output.txt_t')

copy_asset_file(str(src), str(dest), {'var1': 'template'}, renderer)
Expand All @@ -39,7 +39,7 @@ def test_copy_asset_file(tmp_path):

# copy template file to subdir
src = (tmp_path / 'asset.txt_t')
src.write_text('# {{var1}} data')
src.write_text('# {{var1}} data', encoding='utf8')
subdir1 = (tmp_path / 'subdir')
subdir1.mkdir(parents=True, exist_ok=True)

Expand Down