Skip to content

Commit 40b5225

Browse files
authored
Merge pull request #294 from python-cmd2/pytest_forked
Use pytest-forked module for Linux CI
2 parents 388d486 + bca8454 commit 40b5225

File tree

5 files changed

+24
-54
lines changed

5 files changed

+24
-54
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 (not avilable on Windows) for running tests in isolated formed processes,
274+
you 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']
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: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@ 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
@@ -45,29 +44,28 @@ commands =
4544
[testenv:py34]
4645
deps =
4746
mock
48-
pexpect
4947
pyparsing
5048
pyperclip
5149
pytest
50+
pytest-forked
5251
pytest-xdist
5352
six
54-
commands = py.test -v -n2
53+
commands = py.test -v -n2 --forked
5554

5655
[testenv:py35]
5756
deps =
5857
mock
59-
pexpect
6058
pyparsing
6159
pyperclip
6260
pytest
61+
pytest-forked
6362
pytest-xdist
6463
six
65-
commands = py.test -v -n2
64+
commands = py.test -v -n2 --forked
6665

6766
[testenv:py35-win]
6867
deps =
6968
mock
70-
pexpect
7169
pyparsing
7270
pyperclip
7371
pyreadline
@@ -80,21 +78,20 @@ commands = py.test -v -n2
8078
deps =
8179
codecov
8280
mock
83-
pexpect
8481
pyparsing
8582
pyperclip
8683
pytest
8784
pytest-cov
85+
pytest-forked
8886
pytest-xdist
8987
six
9088
commands =
91-
py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing
89+
py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing --forked
9290
codecov
9391

9492
[testenv:py36-win]
9593
deps =
9694
mock
97-
pexpect
9895
pyparsing
9996
pyperclip
10097
pyreadline
@@ -106,11 +103,11 @@ commands = py.test -v -n2
106103
[testenv:py37]
107104
deps =
108105
mock
109-
pexpect
110106
pyparsing
111107
pyperclip
112108
pytest
109+
pytest-forked
113110
pytest-xdist
114111
six
115-
commands = py.test -v -n2
112+
commands = py.test -v -n2 --forked
116113

0 commit comments

Comments
 (0)