Mark flaky test on PyPy with xfail
(#4124) · pypa/setuptools@b8992ad (original) (raw)
``
1
`+
import functools
`
1
2
`import inspect
`
2
3
`import logging
`
3
``
`-
import os
`
``
4
`+
import sys
`
4
5
``
5
6
`import pytest
`
6
7
``
7
8
``
``
9
`+
IS_PYPY = 'pypy' in sys.builtin_module_names
`
``
10
+
``
11
+
8
12
`setup_py = """\
`
9
13
`from setuptools import setup
`
10
14
``
`@@ -38,16 +42,33 @@ def test_verbosity_level(tmp_path, monkeypatch, flag, expected_level):
`
38
42
`assert log_level_name == expected_level
`
39
43
``
40
44
``
``
45
`+
def flaky_on_pypy(func):
`
``
46
`+
@functools.wraps(func)
`
``
47
`+
def _func():
`
``
48
`+
try:
`
``
49
`+
func()
`
``
50
`+
except AssertionError: # pragma: no cover
`
``
51
`+
if IS_PYPY:
`
``
52
`+
msg = "Flaky monkeypatch on PyPy (#4124)"
`
``
53
`+
pytest.xfail(f"{msg}. Original discussion in #3707, #3709.")
`
``
54
`+
raise
`
``
55
+
``
56
`+
return _func
`
``
57
+
``
58
+
``
59
`+
@flaky_on_pypy
`
41
60
`def test_patching_does_not_cause_problems():
`
42
61
`` # Ensure dist.log
is only patched if necessary
``
43
62
``
``
63
`+
import _distutils_hack
`
44
64
`import setuptools.logging
`
45
65
`from distutils import dist
`
46
66
``
47
67
`setuptools.logging.configure()
`
48
68
``
49
``
`-
if os.getenv("SETUPTOOLS_USE_DISTUTILS", "local").lower() == "local":
`
``
69
`+
if _distutils_hack.enabled():
`
50
70
`# Modern logging infra, no problematic patching.
`
``
71
`+
assert dist.file is None or "setuptools" in dist.file
`
51
72
`assert isinstance(dist.log, logging.Logger)
`
52
73
`else:
`
53
74
`assert inspect.ismodule(dist.log)
`