From ca44aab1fa66321b21806b82ad149ae937f27c40 Mon Sep 17 00:00:00 2001 From: Branko Majic Date: Wed, 14 Feb 2018 15:50:46 +0100 Subject: [PATCH] Fix running tests without tox and clean-up/refactor requirements handling for tests/development (issue #644): - Updated package setup to define cleanly all test requirements within it. - Updated package setup to provide ability to install specific set of development/testing/lint testing requirements. - Removed explicit non-leaf dependencies from test requirements. - Updated leaf dependencies to target more specific release (current stable in most cases). This is primarily fixing versions to specific minor release. - Removed explicit list of dependencies from the tox configuration file. Use the dependencies from setup.py instead. - Updated package setup to support running simple python setup.py test for running the tests. - Updated flake8 configuration to exclude all the standard build artefacts, as well as testproject. - It should be possible to directly run pytest for testing now, as well as flake8. - Updated development documentation centering around how to run tests and install dependencies for tests. - Expanded slightly the development documentation hints for running specific tests. --- docs/development/environment.rst | 5 ++--- docs/development/index.rst | 27 +++++++++++++++++++-------- setup.cfg | 5 ++++- setup.py | 32 +++++++++++++++++++++++++++++--- tox.ini | 22 +++------------------- 5 files changed, 57 insertions(+), 34 deletions(-) diff --git a/docs/development/environment.rst b/docs/development/environment.rst index e76f68cb..f09b9fa9 100644 --- a/docs/development/environment.rst +++ b/docs/development/environment.rst @@ -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 diff --git a/docs/development/index.rst b/docs/development/index.rst index e293bbbd..ef095d2c 100644 --- a/docs/development/index.rst +++ b/docs/development/index.rst @@ -70,7 +70,7 @@ 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:: @@ -78,21 +78,30 @@ Ready to contribute? Here's how to set up `django-wiki` for local development. 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 ----------------------- @@ -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 diff --git a/setup.cfg b/setup.cfg index 34ad0b85..f7d02e03 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 \ No newline at end of file diff --git a/setup.py b/setup.py index 11e82f07..d82a4fb6 100755 --- a/setup.py +++ b/setup.py @@ -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", @@ -34,6 +34,30 @@ requirements = [ "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', +] + +setup_requirements = [ + 'pytest-runner', +] + +development_requirements = test_requirements + test_lint_requirements + +extras_requirements = { + 'devel': development_requirements, + 'test': test_requirements, + 'testlint': test_lint_requirements, +} setup( name="wiki", @@ -49,7 +73,7 @@ setup( 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)', @@ -68,5 +92,7 @@ setup( '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, ) diff --git a/tox.ini b/tox.ini index 4143a14d..87333b3d 100644 --- a/tox.ini +++ b/tox.ini @@ -33,24 +33,8 @@ commands = usedevelop = true 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 @@ -60,7 +44,7 @@ basepython = [testenv:lint] basepython = python3.4 -deps = flake8 +deps = .[testlint] commands = flake8 src/wiki flake8 tests/ -- 2.45.2