-
Notifications
You must be signed in to change notification settings - Fork 13
/
test_flakes.py
76 lines (62 loc) · 2.05 KB
/
test_flakes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import sys
pytest_plugins = "pytester",
def test_unused_import(testdir):
testdir.makepyfile("""
import sys
""")
result = testdir.runpytest("--flakes")
assert "'sys' imported but unused" in result.stdout.str()
assert 'passed' not in result.stdout.str()
def test_syntax_error(testdir):
testdir.makeini("""
[pytest]
python_files=check_*.py
""")
testdir.makepyfile("""
for x in []
pass
""")
result = testdir.runpytest("--flakes", "--ignore", testdir.tmpdir)
if sys.version_info >= (3, 10):
assert "1: expected ':'" in result.stdout.str()
else:
assert "1: invalid syntax" in result.stdout.str()
assert 'passed' not in result.stdout.str()
def test_noqa(testdir):
testdir.makeini("""
[pytest]
python_files=check_*.py
""")
testdir.makepyfile("""
import sys # noqa
import os
foo # pragma: no flakes
bar
""")
result = testdir.runpytest("--flakes")
assert "UnusedImport\n'sys' imported but unused" not in result.stdout.str()
assert "UnusedImport\n'os' imported but unused" in result.stdout.str()
assert "UndefinedName\nundefined name 'foo'" not in result.stdout.str()
assert "UndefinedName\nundefined name 'bar'" in result.stdout.str()
assert 'passed' not in result.stdout.str()
def test_pep263(testdir):
testdir.makepyfile(b'\n# encoding=utf-8\n\nsnowman = "\xe2\x98\x83"\n'.decode("utf-8"))
result = testdir.runpytest("--flakes")
assert '1 passed in' in result.stdout.str()
def test_non_py_ext(testdir):
testdir.makefile('', '#!/usr/bin/env python', 'import sys')
result = testdir.runpytest('--flakes')
assert "UnusedImport\n'sys' imported but unused" in result.stdout.str()
assert 'passed' not in result.stdout.str()
def test_flakesignore(testdir):
testdir.makeini("""
[pytest]
flakes-ignore = ImportStarUsed
""")
testdir.makepyfile("""
from os import *
""")
result = testdir.runpytest("--flakes")
assert "ignoring ImportStarUsed" in result.stdout.str()
assert "1: ImportStarUsed" not in result.stdout.str()
assert 'passed' not in result.stdout.str()