Skip to content

Commit 667d477

Browse files
darguetawillmcgugan
authored andcommitted
Migrate tests to Pytest (#337)
* Remove unnecessary requirements.txt * Make complete changeover to pytest * More pytest porting * Fix Appveyor, missing typechecking * Get rid of collections import warning * Mock out AppFS user directories * Remove confusing stack trace change via six * Update changelog * Forgot create=True in a test * Document test changes in Implementing * PR feedback * Add `slow` markers back in * Accumulate coverage across versions * Update changelog * Remove unused import. * Enable branch coverage
1 parent 84719be commit 667d477

23 files changed

+172
-121
lines changed

.travis.yml

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
1+
dist: xenial
12
sudo: false
23
language: python
34

5+
python:
6+
- '2.7'
7+
- '3.4'
8+
- '3.5'
9+
- '3.6'
10+
- '3.7'
11+
# TODO (dargueta): Enable these once we figure out FTP timing issues in PyPy tests
12+
# - 'pypy'
13+
# - 'pypy3.5-7.0'
14+
415
matrix:
516
include:
6-
- python: "2.7"
7-
env:
8-
- SETUPTOOLS=setuptools PIP=pip
9-
- python: "3.7"
10-
env:
11-
- SETUPTOOLS=setuptools PIP=pip
12-
dist: xenial
13-
sudo: true
14-
install:
15-
- pip install mypy
16-
- make typecheck
17-
- python: "3.6"
18-
install:
19-
- pip install mypy
20-
- make typecheck
21-
env:
22-
- SETUPTOOLS=setuptools PIP=pip
23-
- python: "3.5"
24-
env:
25-
- SETUPTOOLS=setuptools PIP=pip
26-
- python: "3.4"
27-
env:
28-
- SETUPTOOLS=setuptools PIP=pip
17+
- name: 'Type checking'
18+
python: '3.7'
19+
env: TOXENV=typecheck
2920

3021
before_install:
31-
- pip install $SETUPTOOLS $PIP -U
22+
- pip install -U tox tox-travis
3223
- pip --version
3324
- pip install -r testrequirements.txt
3425
- pip freeze
@@ -40,5 +31,4 @@ after_success:
4031
- coveralls
4132

4233
# command to run tests
43-
script:
44-
- nosetests -v --with-coverage --cover-package=fs tests
34+
script: tox

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
- Fixed tests leaving tmp files
1313
- Fixed typing issues
1414
- Fixed link namespace returning bytes
15+
- Fixed abstract class import from `collections` which would break on Python 3.8
16+
- Fixed incorrect imports of `mock` on Python 3
17+
- Removed some unused imports and unused `requirements.txt` file
18+
- Added mypy checks to Travis
19+
20+
### Changed
21+
22+
Entire test suite has been migrated to [pytest](https://docs.pytest.org/en/latest/).
23+
Closes [#327](https://github.com/PyFilesystem/pyfilesystem2/issues/327).
1524

1625
## [2.4.10] - 2019-07-29
1726

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ environment:
2020

2121
install:
2222
# We need wheel installed to build wheels
23-
- "%PYTHON%\\python.exe -m pip install nose psutil pyftpdlib mock"
23+
- "%PYTHON%\\python.exe -m pip install pytest pytest-randomly pytest-cov psutil pyftpdlib mock"
2424
- "%PYTHON%\\python.exe setup.py install"
2525

2626
build: off
2727

2828
test_script:
29-
- "%PYTHON%\\python.exe -m nose tests -v"
29+
- "%PYTHON%\\python.exe -m pytest -v tests"

docs/source/implementers.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ You may also want to override some of the methods in the test suite for more tar
5454
.. autoclass:: fs.test.FSTestCases
5555
:members:
5656

57+
.. note::
58+
59+
As of version 2.4.11 this project uses `pytest <https://pytest.org/en/latest/>`_ to run its tests.
60+
While it's completely compatible with ``unittest``-style tests, it's much more powerful and
61+
feature-rich. We suggest you take advantage of it and its plugins in new tests you write, rather
62+
than sticking to strict ``unittest`` features. For benefits and limitations, see `here <https://pytest.org/en/latest/unittest.html>`_.
63+
5764

5865
.. _essential-methods:
5966

fs/error_tools.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import errno
99
import platform
1010
import sys
11-
import typing
1211
from contextlib import contextmanager
1312

1413
from six import reraise, PY3
@@ -116,4 +115,4 @@ def unwrap_errors(path_replace):
116115
e.path = path_replace.get(e.path, e.path)
117116
else:
118117
e.path = path_replace
119-
reraise(type(e), e)
118+
raise

fs/test.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from __future__ import absolute_import
99
from __future__ import unicode_literals
1010

11-
import collections
1211
from datetime import datetime
1312
import io
1413
import itertools
@@ -17,6 +16,8 @@
1716
import os
1817
import time
1918

19+
import pytest
20+
2021
import fs.copy
2122
import fs.move
2223
from fs import ResourceType, Seek
@@ -30,6 +31,11 @@
3031
import six
3132
from six import text_type
3233

34+
if six.PY2:
35+
import collections as collections_abc
36+
else:
37+
import collections.abc as collections_abc
38+
3339

3440
UNICODE_TEXT = """
3541
@@ -1285,7 +1291,7 @@ def test_scandir(self):
12851291

12861292
# Check scandir returns an iterable
12871293
iter_scandir = self.fs.scandir("/")
1288-
self.assertTrue(isinstance(iter_scandir, collections.Iterable))
1294+
self.assertTrue(isinstance(iter_scandir, collections_abc.Iterable))
12891295
self.assertEqual(list(iter_scandir), [])
12901296

12911297
# Check scanning
@@ -1298,7 +1304,7 @@ def test_scandir(self):
12981304
self.fs.create("bar")
12991305
self.fs.makedir("dir")
13001306
iter_scandir = self.fs.scandir("/")
1301-
self.assertTrue(isinstance(iter_scandir, collections.Iterable))
1307+
self.assertTrue(isinstance(iter_scandir, collections_abc.Iterable))
13021308

13031309
scandir = sorted(
13041310
[r.raw for r in iter_scandir], key=lambda info: info["basic"]["name"]
@@ -1790,7 +1796,7 @@ def test_tree(self):
17901796

17911797
def test_unicode_path(self):
17921798
if not self.fs.getmeta().get("unicode_paths", False):
1793-
self.skipTest("the filesystem does not support unicode paths.")
1799+
return pytest.skip("the filesystem does not support unicode paths.")
17941800

17951801
self.fs.makedir("földér")
17961802
self.fs.writetext("☭.txt", "Smells like communism.")
@@ -1813,10 +1819,10 @@ def test_unicode_path(self):
18131819
def test_case_sensitive(self):
18141820
meta = self.fs.getmeta()
18151821
if "case_insensitive" not in meta:
1816-
self.skipTest("case sensitivity not known")
1822+
return pytest.skip("case sensitivity not known")
18171823

18181824
if meta.get("case_insensitive", False):
1819-
self.skipTest("the filesystem is not case sensitive.")
1825+
return pytest.skip("the filesystem is not case sensitive.")
18201826

18211827
self.fs.makedir("foo")
18221828
self.fs.makedir("Foo")
@@ -1846,4 +1852,3 @@ def test_hash(self):
18461852
self.assertEqual(
18471853
foo_fs.hash("hashme.txt", "md5"), "9fff4bb103ab8ce4619064109c54cb9c"
18481854
)
1849-

fs/walk.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
from collections import deque
1313
from collections import namedtuple
1414

15-
import six
16-
1715
from ._repr import make_repr
1816
from .errors import FSError
1917
from .path import abspath
@@ -295,7 +293,7 @@ def _scan(
295293
yield info
296294
except FSError as error:
297295
if not self.on_error(dir_path, error):
298-
six.reraise(type(error), error)
296+
raise
299297

300298
def walk(
301299
self,

requirements.txt

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

setup.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ warn_return_any = false
3434
disallow_untyped_defs = false
3535

3636
[coverage:run]
37+
branch = true
3738
omit = fs/test.py
39+
source = fs
3840

3941
[coverage:report]
4042
show_missing = true
43+
skip_covered = true
4144
exclude_lines =
4245
pragma: no cover
4346
if False:
4447
@typing.overload
4548

49+
[tool:pytest]
50+
markers =
51+
slow: marks tests as slow (deselect with '-m "not slow"')

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
package_data={"fs": ["py.typed"]},
4040
zip_safe=False,
4141
platforms=["any"],
42-
test_suite="nose.collector",
43-
tests_require=["appdirs", "mock", "pytz", "pyftpdlib"],
4442
url="https://github.com/PyFilesystem/pyfilesystem2",
4543
version=__version__,
4644
)

0 commit comments

Comments
 (0)