Skip to content

Commit

Permalink
Move tests out of package and into top-level directory
Browse files Browse the repository at this point in the history
This follows the "Tests outside application code" pattern documented in
the pytest guides. See:
https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#tests-outside-application-code

> This has the following benefits:
>
> - Your tests can run against an installed version after executing pip
> install ..
>
> - Your tests can run against the local copy with an editable install
> after executing pip install --editable ..
>
> - If you don’t use an editable install and are relying on the fact
> that Python by default puts the current directory in sys.path to
> import your package, you can execute python -m pytest to execute the
> tests against the local copy directly, without using pip.

This keeps tests separate from actual library code. End users don't need
the tests mixed in with the installed packages. Instead, tests are only
interesting to library developers and packagers. The tests remain
available, just moved.
  • Loading branch information
jdufresne committed Jun 26, 2022
1 parent 66291d0 commit 7876fe1
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
branch = True
source = codespell_lib
include = */codespell_lib/*
omit = */codespell_lib/tests/*
omit = */tests/*
4 changes: 2 additions & 2 deletions .github/workflows/codespell-private.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
- run: python setup.py install
- run: codespell --help
- run: make check
- run: codespell --check-filenames --skip="./.git/*,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*"
- run: codespell --check-filenames --skip="./.git/*,*.pyc,./tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*"
# this file has an error
- run: "! codespell codespell_lib/tests/test_basic.py"
- run: "! codespell tests/test_basic.py"
- run: codecov

make-check-dictionaries:
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include codespell_lib/__init__.py
recursive-include codespell_lib *.py
recursive-include tests *.py
include codespell_lib/data/dictionary*.txt
include codespell_lib/data/linux-kernel.exclude
include COPYING
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ check-dictionaries:
fi; \
done
@if command -v pytest > /dev/null; then \
pytest codespell_lib/tests/test_dictionary.py; \
pytest tests/test_dictionary.py; \
else \
echo "Test dependencies not present, install using 'pip install -e \".[dev]\"'"; \
exit 1; \
Expand All @@ -54,7 +54,7 @@ flake8:
flake8

pytest:
pytest codespell_lib
pytest

pypi:
python setup.py sdist register upload
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build: false # Not a C# project, build stuff at the test step instead.
test_script:
- "codespell --help"
- "flake8"
- "pytest codespell_lib"
- "pytest"

on_success:
- "codecov"
Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
os.path.join('data', 'dictionary*.txt'),
os.path.join('data', 'linux-kernel.exclude'),
]},
exclude_package_data={'codespell_lib': [
os.path.join('tests', '*'),
]},
entry_points={
'console_scripts': [
'codespell = codespell_lib:_script_main'
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pytest

import codespell_lib
from codespell_lib._codespell import _builtin_dictionaries
from codespell_lib._codespell import supported_languages

Expand All @@ -32,7 +33,7 @@
global_pairs = set()

# Filename, should be seen as errors in aspell or not
_data_dir = op.join(op.dirname(__file__), '..', 'data')
_data_dir = op.join(op.dirname(codespell_lib.__file__), 'data')
_fnames_in_aspell = [
(op.join(_data_dir, 'dictionary%s.txt' % d[2]), d[3:5], d[5:7])
for d in _builtin_dictionaries]
Expand Down

0 comments on commit 7876fe1

Please sign in to comment.