Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved test dependency handling, removal of wrapper testing script, and fixes for running pytest directly (issue #644) #781

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion MANIFEST.in
@@ -1,7 +1,6 @@
include COPYING
include README.rst
include setup.cfg
include runtests.py
recursive-include src *.html *.txt *.png *.js *.css *.gif *.less *.mo *.po *.otf *.svg *.woff *.woff2 *.eot *.ttf
prune src/wiki/attachments
prune src/wiki/images
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -51,7 +51,7 @@ lint: ## Check python code conventions
flake8 src/wiki tests/

test: ## Run automated test suite
./runtests.py
pytest

test-all: ## Run tests on all supported Python environments
tox
Expand Down
5 changes: 2 additions & 3 deletions docs/development/environment.rst
Expand Up @@ -7,6 +7,5 @@ Setting up a development environment
* Install the requirements::

$ pip install --upgrade pip setuptools
$ pip install -e .
$ pip install pytest pytest-django pytest-pythonpath pytest-cov mock django-functest

$ pip install -e .[devel]
$ pip install tox
27 changes: 19 additions & 8 deletions docs/development/index.rst
Expand Up @@ -70,29 +70,38 @@ Ready to contribute? Here's how to set up `django-wiki` for local development.

$ mkvirtualenv django-wiki
$ cd django-wiki/
$ python setup.py develop
$ pip install -e .[devel]

4. Create a branch for local development::

$ git checkout -b name-of-your-bugfix-or-feature

Now you can make your changes locally.

5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox::
5. As you are making changes you may want to verify that changes are
passing all the relevant styling and functional/unit tests::

$ tox -e lint
$ py.test # Run tests in current environment
$ tox
$ flake8
$ pytest

6. When you're done making changes, perform one final round of
testing, and also ensure relevant tests pass with all supported
Python versions with tox::

$ flake8
$ pytest
$ tox -e lint # Runs linter within isolated environment
$ tox # Runs all tests that pytest would run, just with various Python/Django combinations

To get flake8 and tox, just pip install them into your virtualenv.

6. Commit your changes and push your branch to GitHub::
7. Commit your changes and push your branch to GitHub::

$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-feature

7. Submit a pull request through the GitHub website.
8. Submit a pull request through the GitHub website.

Pull Request Guidelines
-----------------------
Expand All @@ -112,7 +121,9 @@ Tips

To run a subset of tests::

$ py.test tests.test_django-wiki
$ pytest tests/core/test_basic.py # All tests from a single file.
$ pytest tests/core/test_basic.py::URLPathTests # All tests from a single class.
$ pytest tests/core/test_basic.py::URLPathTests::test_manager # Just one test.


Roadmap
Expand Down
23 changes: 17 additions & 6 deletions docs/development/testing.rst
Expand Up @@ -4,19 +4,30 @@ Tests
Running tests
-------------

To run django-wiki's tests, run ``make test`` or ``./runtests.py``
To run django-wiki's tests, run ``make test`` or ``pytest``

If you want to test for more **environments**, install "tox"
(``pip install tox``) and then just run ``tox`` to run the test
suite on multiple environments.

To run **specific tests**, see ``./runtests.py --help``.
To run **specific tests**, see ``pytest --help``.

To include Selenium tests, you need to install `chromedriver
<https://sites.google.com/a/chromium.org/chromedriver/>`_ and run
``./runtests.py --include-selenium``. For tox, do::
To include Selenium tests, you need to have ``Xvfb`` installed
(usually via system-provided package manager), `chromedriver
<https://sites.google.com/a/chromium.org/chromedriver/>`_ and set the
environment variable ``INCLUDE_SELENIUM_TESTS=1``. For example, run
tests with (depending on whether you want to test directly or via
tox)::

INCLUDE_SELENIUM_TESTS=1 tox
INCLUDE_SELENIUM_TESTS=1 pytest
INCLUDE_SELENIUM_TESTS=1 tox

If you wish to also show the browser window while running the
functional tests, set the environment variable
``SELENIUM_SHOW_BROWSER=1`` in *addition* to
``INCLUDE_SELENIUM_TESTS=1``, for example::

INCLUDE_SELENIUM_TESTS=1 SELENIUM_SHOW_BROWSER=1 pytest


Writing tests
Expand Down
58 changes: 0 additions & 58 deletions runtests.py

This file was deleted.

5 changes: 4 additions & 1 deletion setup.cfg
Expand Up @@ -5,7 +5,10 @@ universal = 1
ignore = E501
max-line-length = 160
max-complexity = 10
exclude = */*migrations
exclude = .svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg,*/*migrations,testproject

[metadata]
description-file = README.rst

[aliases]
test=pytest
32 changes: 29 additions & 3 deletions setup.py
Expand Up @@ -23,7 +23,7 @@ def get_path(fname):
return os.path.join(os.path.dirname(__file__), fname)


requirements = [
install_requirements = [
"Django>=1.11,<2.0",
"bleach>=1.5,<2",
"Pillow",
Expand All @@ -34,6 +34,30 @@ def get_path(fname):
"Markdown>=2.6,<2.7",
]

test_requirements = [
'django-functest>=1.0,<1.1',
'mock>=2.0,<2.1',
'pytest>=3.4,<3.5',
'pytest-django>=3.1,<3.2',
'pytest-cov>=2.4,<2.5',
'pytest-pythonpath>=0.7,<0.8',
]

test_lint_requirements = [
'flake8>=3.5,<3.6',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! Actually flake8 has been introducing changes that broke linting out of no where... it's best to be explicit about which version of flake8 that linting is supposed to conform to (together with specs in setup.cfg)

]

setup_requirements = [
'pytest-runner',
]

development_requirements = test_requirements + test_lint_requirements

extras_requirements = {
'devel': development_requirements,
'test': test_requirements,
'testlint': test_lint_requirements,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this pattern!! Really nice overview of requirements, everything maintained in the same place, and the loosest form of dependencies that affect distribution and testing at the same time.


setup(
name="wiki",
Expand All @@ -49,7 +73,7 @@ def get_path(fname):
py_modules=[os.path.splitext(os.path.basename(path))[0] for path in glob('src/*.py')],
long_description=open('README.rst').read(),
zip_safe=False,
install_requires=requirements,
install_requires=install_requirements,
classifiers=[
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
Expand All @@ -68,5 +92,7 @@ def get_path(fname):
'Topic :: Software Development :: Libraries :: Application Frameworks',
],
include_package_data=True,
test_suite='runtests',
setup_requires=setup_requirements,
tests_require=test_requirements,
extras_require=extras_requirements,
)
26 changes: 5 additions & 21 deletions tox.ini
Expand Up @@ -28,29 +28,13 @@ commands =
# Test that there are no migrations needed -- on Django 1.11, we can
# use --check and remove the '!' which likely doesn't work on Windows
sh -c '! testproject/manage.py makemigrations --dry-run --exit --noinput'
{toxinidir}/runtests.py --basetemp={envtmpdir} --ds=tests.settings --cov=src/wiki --cov-config .coveragerc {posargs}
pytest --basetemp={envtmpdir} --ds=tests.settings --cov={envsitepackagesdir}/wiki --cov-config .coveragerc {posargs}

usedevelop = true
usedevelop = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very important addition!! Great work!!


deps =
coverage
pytest==3.0.7
pytest-django==3.1.2
pytest-pythonpath==0.7.1
pytest-cov==2.4.0
Pillow==2.3.0
django-classy-tags==0.4
mock>=2.0
Markdown==2.6.7
django_nyt==1.0
bleach==1.5.0
django111: Django==1.11
django-mptt==0.8.6
django-sekizai==0.10.0
sorl-thumbnail==12.3
django-functest==1.0.2
django-webtest==1.9.2
WebTest==2.0.28
.[test]
django111: Django>=1.11,<2.0

basepython =
py34: python3.4
Expand All @@ -60,7 +44,7 @@ basepython =

[testenv:lint]
basepython = python3.4
deps = flake8
deps = .[testlint]
commands =
flake8 src/wiki
flake8 tests/