Skip to content

Commit 8eebaae

Browse files
committed
Added use of pytest-forked to CI unit test runs
Due to apparent bugs in pyparsing, this can significantly speed up unit test execution. Also: - Removed use of pexpect in unit tests
1 parent 388d486 commit 8eebaae

File tree

5 files changed

+30
-57
lines changed

5 files changed

+30
-57
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 0.8.1 (TBD, 2018)
1+
## 0.8.1 (March TBD, 2018)
22

33
* Bug Fixes
44
* Fixed a bug if a non-existent **do_*** method was added to the ``exclude_from_help`` list
@@ -16,7 +16,7 @@
1616
* ``exclude_from_help`` and ``excludeFromHistory`` are now instance instead of class attributes
1717
* Added flag and index based tab completion helper functions
1818
* See [tab_completion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/tab_completion.py)
19-
* Attributes Removed
19+
* Attributes Removed (**can cause breaking changes**)
2020
* ``abbrev`` - Removed support for abbreviated commands
2121
* Good tab completion makes this unnecessary
2222

CONTRIBUTING.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ The tables below list all prerequisites along with the minimum required version
6565
### Optional prerequisites for enhanced unit test features
6666
| Prerequisite | Minimum Version |
6767
| ------------------------------------------- | --------------- |
68+
| [pytest-forked](https://pypi.python.org/pypi/pytest-forked)| `0.2` |
6869
| [pytest-xdist](https://pypi.python.org/pypi/pytest-xdist)| `1.15` |
6970
| [pytest-cov](https://pypi.python.org/pypi/pytest-cov) | `1.8` |
7071

@@ -201,7 +202,7 @@ pip install -U pytest mock
201202
pip install -U sphinx sphinx-rtd-theme
202203

203204
# Install optional prerequisites for running unit tests in parallel and doing code coverage analysis
204-
pip install -U pytest-xdist pytest-cov
205+
pip install -U pytest-xdist pytest-cov pytest-forked
205206
```
206207

207208
For doing cmd2 development, you actually do NOT want to have cmd2 installed as a Python package.
@@ -269,6 +270,13 @@ py.test -n4
269270
```
270271
where `4` should be replaced by the number of parallel threads you wish to run for testing.
271272

273+
If you have the `pytest-forked` pytest plugin for running tests in isolated formed processes, you
274+
can speed things up even further:
275+
276+
```shell
277+
py.test -nauto --forked
278+
```
279+
272280
#### Measuring code coverage
273281

274282
Code coverage can be measured as follows:
@@ -390,11 +398,11 @@ how to do it.
390398

391399
6. Indicate what local testing you have done (e.g. what OS and version(s) of Python did you run the
392400
unit test suite with)
393-
401+
394402
7. Creating the PR causes our continuous integration (CI) systems to automatically run all of the
395403
unit tests on all supported OSes and all supported versions of Python. You should watch your PR
396404
to make sure that all unit tests pass on Both TravisCI (Linux) and AppVeyor (Windows).
397-
405+
398406
8. If any unit tests fail, you should look at the details and fix the failures. You can then push
399407
the fix to the same branch in your fork and the PR will automatically get updated and the CI system
400408
will automatically run all of the unit tests again.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
INSTALL_REQUIRES += ['subprocess32']
7878

7979
# unittest.mock was added in Python 3.3. mock is a backport of unittest.mock to all versions of Python
80-
TESTS_REQUIRE = ['mock', 'pytest', 'pexpect']
80+
TESTS_REQUIRE = ['mock', 'pytest', 'pytest-xdist', 'pytest-forked']
8181
DOCS_REQUIRE = ['sphinx', 'sphinx_rtd_theme', 'pyparsing', 'pyperclip', 'six']
8282

8383
setup(

tests/test_cmd2.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import tempfile
1212

1313
import mock
14-
import pexpect
1514
import pytest
1615
import six
1716

@@ -1502,37 +1501,3 @@ def test_poutput_none(base_app):
15021501
out = base_app.stdout.buffer
15031502
expected = ''
15041503
assert out == expected
1505-
1506-
1507-
@pytest.mark.skipif(sys.platform == 'win32' or sys.platform.startswith('lin'),
1508-
reason="pexpect doesn't have a spawn() function on Windows and readline doesn't work on TravisCI")
1509-
def test_persistent_history(request):
1510-
"""Will run on macOS to verify expected persistent history behavior."""
1511-
test_dir = os.path.dirname(request.module.__file__)
1512-
persistent_app = os.path.join(test_dir, '..', 'examples', 'persistent_history.py')
1513-
1514-
python = 'python3'
1515-
if six.PY2:
1516-
python = 'python2'
1517-
1518-
command = '{} {}'.format(python, persistent_app)
1519-
1520-
# Start an instance of the persistent history example and send it a few commands
1521-
child = pexpect.spawn(command)
1522-
prompt = 'ph> '
1523-
child.expect(prompt)
1524-
child.sendline('help')
1525-
child.expect(prompt)
1526-
child.sendline('help history')
1527-
child.expect(prompt)
1528-
child.sendline('quit')
1529-
child.close()
1530-
1531-
# Start a 2nd instance of the persistent history example and send it an up arrow to verify persistent history
1532-
up_arrow = '\x1b[A'
1533-
child2 = pexpect.spawn(command)
1534-
child2.expect(prompt)
1535-
child2.send(up_arrow)
1536-
child2.expect('quit')
1537-
assert child2.after == b'quit'
1538-
child2.close()

tox.ini

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,104 +13,104 @@ setenv =
1313
deps =
1414
codecov
1515
mock
16-
pexpect
1716
pyparsing
1817
pyperclip
1918
pytest
2019
pytest-cov
20+
pytest-forked
2121
pytest-xdist
2222
six
2323
subprocess32
2424
commands =
25-
py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing
25+
py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing --forked
2626
codecov
2727

2828
[testenv:py27-win]
2929
deps =
3030
codecov
3131
mock
32-
pexpect
3332
pyparsing
3433
pyperclip
3534
pyreadline
3635
pytest
3736
pytest-cov
37+
pytest-forked
3838
pytest-xdist
3939
six
4040
subprocess32
4141
commands =
42-
py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing
42+
py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing --forked
4343
codecov
4444

4545
[testenv:py34]
4646
deps =
4747
mock
48-
pexpect
4948
pyparsing
5049
pyperclip
5150
pytest
51+
pytest-forked
5252
pytest-xdist
5353
six
54-
commands = py.test -v -n2
54+
commands = py.test -v -n2 --forked
5555

5656
[testenv:py35]
5757
deps =
5858
mock
59-
pexpect
6059
pyparsing
6160
pyperclip
6261
pytest
62+
pytest-forked
6363
pytest-xdist
6464
six
65-
commands = py.test -v -n2
65+
commands = py.test -v -n2 --forked
6666

6767
[testenv:py35-win]
6868
deps =
6969
mock
70-
pexpect
7170
pyparsing
7271
pyperclip
7372
pyreadline
7473
pytest
74+
pytest-forked
7575
pytest-xdist
7676
six
77-
commands = py.test -v -n2
77+
commands = py.test -v -n2 --forked
7878

7979
[testenv:py36]
8080
deps =
8181
codecov
8282
mock
83-
pexpect
8483
pyparsing
8584
pyperclip
8685
pytest
8786
pytest-cov
87+
pytest-forked
8888
pytest-xdist
8989
six
9090
commands =
91-
py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing
91+
py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing --forked
9292
codecov
9393

9494
[testenv:py36-win]
9595
deps =
9696
mock
97-
pexpect
9897
pyparsing
9998
pyperclip
10099
pyreadline
101100
pytest
101+
pytest-forked
102102
pytest-xdist
103103
six
104-
commands = py.test -v -n2
104+
commands = py.test -v -n2 --forked
105105

106106
[testenv:py37]
107107
deps =
108108
mock
109-
pexpect
110109
pyparsing
111110
pyperclip
112111
pytest
112+
pytest-forked
113113
pytest-xdist
114114
six
115-
commands = py.test -v -n2
115+
commands = py.test -v -n2 --forked
116116

0 commit comments

Comments
 (0)