Skip to content

Commit 7c04190

Browse files
authored
Merge pull request #1174 from PyCQA/testsuite-pytest
port --testsuite to pytest
2 parents 68bc190 + 57dc8de commit 7c04190

File tree

13 files changed

+154
-241
lines changed

13 files changed

+154
-241
lines changed

CONTRIBUTING.rst

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,28 @@ GitHub has an excellent `guide`_.
7070

7171
The current tests are written in 2 styles:
7272

73-
* standard xUnit based only on stdlib unittest
74-
* functional test using a custom framework and executed by the
75-
pycodestyle itself when installed in dev mode.
73+
* pytest tests
74+
* functional test using a custom framework
7675

7776

78-
Running unittest
79-
~~~~~~~~~~~~~~~~
77+
Running tests
78+
~~~~~~~~~~~~~
8079

81-
The tests are written using stdlib ``unittest`` module, the existing tests
80+
The tests are written using ``pytest``, the existing tests
8281
include unit, integration and functional tests.
8382

8483
To run the tests::
8584

86-
$ python setup.py test
85+
$ pytest testsuite
8786

8887
Running functional
8988
~~~~~~~~~~~~~~~~~~
9089

91-
When installed in dev mode, pycodestyle will have the ``--testsuite`` option
92-
which can be used to run the tests::
93-
9490
$ pip install -e .
9591
$ # Run all tests.
96-
$ pycodestyle --testsuite testsuite
92+
$ pytest testsuite
9793
$ # Run a subset of the tests.
98-
$ pycodestyle --testsuite testsuite/E30.py
94+
$ pytest testsuite -k testing/data/E30.py
9995

10096

10197
.. _virtualenv: http://docs.python-guide.org/en/latest/dev/virtualenvs/

docs/developer.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ the docstring, you can use ``\n`` for newline and ``\t`` for tab.
9797

9898
Then be sure to pass the tests::
9999

100-
$ python pycodestyle.py --testsuite testsuite
101-
$ pytest testsuite/test_self_doctest.py
100+
$ pytest testsuite
102101
$ python pycodestyle.py --verbose pycodestyle.py
103102

104103
When contributing to pycodestyle, please observe our `Code of Conduct`_.

pycodestyle.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
USER_CONFIG = None
8585

8686
PROJECT_CONFIG = ('setup.cfg', 'tox.ini')
87-
TESTSUITE_PATH = os.path.join(os.path.dirname(__file__), 'testsuite')
8887
MAX_LINE_LENGTH = 79
8988
# Number of blank lines between various code parts.
9089
BLANK_LINES_CONFIG = {
@@ -2301,8 +2300,7 @@ def __init__(self, *args, **kwargs):
23012300
options.reporter = BaseReport if options.quiet else StandardReport
23022301

23032302
options.select = tuple(options.select or ())
2304-
if not (options.select or options.ignore or
2305-
options.testsuite) and DEFAULT_IGNORE:
2303+
if not (options.select or options.ignore) and DEFAULT_IGNORE:
23062304
# The default choice: ignore controversial checks
23072305
options.ignore = tuple(DEFAULT_IGNORE.split(','))
23082306
else:
@@ -2472,9 +2470,6 @@ def get_parser(prog='pycodestyle', version=__version__):
24722470
help="report changes only within line number ranges in "
24732471
"the unified diff received on STDIN")
24742472
group = parser.add_option_group("Testing Options")
2475-
if os.path.exists(TESTSUITE_PATH):
2476-
group.add_option('--testsuite', metavar='dir',
2477-
help="run regression tests from dir")
24782473
group.add_option('--benchmark', action='store_true',
24792474
help="measure processing speed")
24802475
return parser
@@ -2551,7 +2546,6 @@ def read_config(options, args, arglist, parser):
25512546

25522547
# Third, overwrite with the command-line options
25532548
(options, __) = parser.parse_args(arglist, values=new_options)
2554-
options.testsuite = False
25552549
return options
25562550

25572551

@@ -2584,17 +2578,14 @@ def process_options(arglist=None, parse_argv=False, config_file=None,
25842578
if verbose is not None:
25852579
options.verbose = verbose
25862580

2587-
if options.ensure_value('testsuite', False):
2588-
args.append(options.testsuite)
2589-
else:
2590-
if parse_argv and not args:
2591-
if options.diff or any(os.path.exists(name)
2592-
for name in PROJECT_CONFIG):
2593-
args = ['.']
2594-
else:
2595-
parser.error('input not specified')
2596-
options = read_config(options, args, arglist, parser)
2597-
options.reporter = parse_argv and options.quiet == 1 and FileReport
2581+
if parse_argv and not args:
2582+
if options.diff or any(os.path.exists(name)
2583+
for name in PROJECT_CONFIG):
2584+
args = ['.']
2585+
else:
2586+
parser.error('input not specified')
2587+
options = read_config(options, args, arglist, parser)
2588+
options.reporter = parse_argv and options.quiet == 1 and FileReport
25982589

25992590
options.filename = _parse_multi_options(options.filename)
26002591
options.exclude = normalize_paths(options.exclude)
@@ -2639,21 +2630,14 @@ def _main():
26392630
style_guide = StyleGuide(parse_argv=True)
26402631
options = style_guide.options
26412632

2642-
if options.testsuite:
2643-
from testsuite.support import run_tests
2644-
report = run_tests(style_guide)
2645-
else:
2646-
report = style_guide.check_files()
2633+
report = style_guide.check_files()
26472634

26482635
if options.statistics:
26492636
report.print_statistics()
26502637

26512638
if options.benchmark:
26522639
report.print_benchmark()
26532640

2654-
if options.testsuite and not options.quiet:
2655-
report.print_results()
2656-
26572641
if report.total_errors:
26582642
if options.count:
26592643
sys.stderr.write(str(report.total_errors) + '\n')

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ max_doc_length = 72
4848
[coverage:run]
4949
plugins = covdefaults
5050
omit = testsuite/data
51-
parallel = true
5251

5352
[coverage:report]
5453
fail_under = 93

testing/data/W29.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class Foo(object):
1414
#: W191 W292 noeol
1515
if False:
1616
pass # indented with tabs
17-
#: W292:1:36 noeol
18-
# This line doesn't have a linefeed
1917
#: W292:1:5 E225:1:2 noeol
2018
1+ 1
2119
#: W292:1:27 E261:1:12 noeol

testing/data/python39.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#: W292:1:70 noeol
2+
# This line doesn't have a linefeed (in 3.8 this is reported thrice!)

testing/support.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
from __future__ import annotations
22

3+
import os.path
4+
35
from pycodestyle import BaseReport
46
from pycodestyle import StyleGuide
57

8+
ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
9+
610

711
class InMemoryReport(BaseReport):
812
"""
@@ -23,7 +27,7 @@ def error(self, line_number, offset, text, check):
2327

2428

2529
def errors_from_src(src: str) -> list[str]:
26-
guide = StyleGuide(select=('E', 'W'))
30+
guide = StyleGuide(select=('E', 'W'), max_doc_length=72)
2731
reporter = guide.init_report(InMemoryReport)
2832
guide.input_file(
2933
filename='in-memory-test-file.py',

testsuite/support.py

Lines changed: 0 additions & 151 deletions
This file was deleted.

testsuite/test_all.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
import os.path
2-
import unittest
32

43
import pycodestyle
5-
from testsuite.support import init_tests
6-
from testsuite.support import ROOT_DIR
4+
from testing.support import ROOT
75

86

9-
class PycodestyleTestCase(unittest.TestCase):
10-
"""Test the standard errors and warnings (E and W)."""
11-
12-
def setUp(self):
13-
self._style = pycodestyle.StyleGuide(
14-
paths=[os.path.join(ROOT_DIR, 'testsuite')],
15-
select='E,W', quiet=True)
16-
17-
def test_checkers_testsuite(self):
18-
init_tests(self._style)
19-
report = self._style.check_files()
20-
self.assertFalse(report.total_errors,
21-
msg='%s failure(s)' % report.total_errors)
22-
23-
def test_own_dog_food(self):
24-
files = [pycodestyle.__file__.rstrip('oc'), __file__.rstrip('oc'),
25-
os.path.join(ROOT_DIR, 'setup.py')]
26-
report = self._style.init_report(pycodestyle.StandardReport)
27-
report = self._style.check_files(files)
28-
self.assertEqual(list(report.messages.keys()), ['W504'],
29-
msg='Failures: %s' % report.messages)
7+
def test_own_dog_food():
8+
style = pycodestyle.StyleGuide(select='E,W', quiet=True)
9+
files = [pycodestyle.__file__, __file__, os.path.join(ROOT, 'setup.py')]
10+
report = style.init_report(pycodestyle.StandardReport)
11+
report = style.check_files(files)
12+
assert list(report.messages) == ['W504'], f'Failures: {report.messages}'

0 commit comments

Comments
 (0)