From 9857693ebf40ee747691dd9c9f281a92c69ba303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Schoentgen?= Date: Fri, 11 Jun 2021 20:55:26 +0200 Subject: [PATCH] Use a more modern approach to run tests (#1089) Running tests through `python setup.py test` is deprecated: > WARNING: Testing via this command is deprecated and will be removed > in a future version. Users looking for a generic test entry point > independent of test runner are encouraged to use tox. I am not in favor of moving back to `tox`, we should simply run tests using `python -m pytest` (or `make test`) and that's it. A new extra was added, `dev`, to install development requirements: $ python -m pip install --upgrade --editable '.[dev]' --- .github/workflows/build.yml | 4 ++-- CONTRIBUTING.rst | 2 +- Makefile | 5 ++--- requirements-dev.txt | 11 ---------- setup.py | 44 +++++++++++++------------------------ 5 files changed, 20 insertions(+), 46 deletions(-) delete mode 100644 requirements-dev.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff937094..44d88d44 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,5 +30,5 @@ jobs: with: python-version: ${{ matrix.python-version }} - run: python -m pip install --upgrade pip setuptools wheel - - run: python -m pip install --upgrade --editable . - - run: python setup.py test + - run: python -m pip install --upgrade '.[dev]' + - run: python -m pytest --verbose ./httpie ./tests diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 7a46c199..1707fd7f 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -193,7 +193,7 @@ Install HTTPie in editable mode with all the dependencies: .. code-block:: powershell - python -m pip install --upgrade --editable . -r requirements-dev.txt + python -m pip install --upgrade --editable '.[dev]' You should now see ``(httpie)`` next to your shell prompt, and the ``http`` command should point to your development copy: diff --git a/Makefile b/Makefile index 6bc1816b..cc4deff2 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,6 @@ ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) VERSION=$(shell grep __version__ httpie/__init__.py) -REQUIREMENTS=requirements-dev.txt H1="\n\n\033[0;32m\#\#\# " H1END=" \#\#\# \033[0m\n" @@ -28,7 +27,7 @@ all: uninstall-httpie install test install: venv @echo $(H1)Installing dev requirements$(H1END) - $(VENV_PIP) install --upgrade -r $(REQUIREMENTS) + $(VENV_PIP) install --upgrade --editable '.[dev]' @echo $(H1)Installing HTTPie$(H1END) $(VENV_PIP) install --upgrade --editable . @@ -123,7 +122,7 @@ pycodestyle: codestyle codestyle: @echo $(H1)Running flake8$(H1END) - @[ -f $(VENV_BIN)/flake8 ] || $(VENV_PIP) install --upgrade -r $(REQUIREMENTS) + @[ -f $(VENV_BIN)/flake8 ] || $(VENV_PIP) install --upgrade --editable '.[dev]' $(VENV_BIN)/flake8 httpie/ tests/ extras/ *.py @echo diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index d5cff049..00000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,11 +0,0 @@ -flake8 -flake8-comprehensions -flake8-deprecated -flake8-mutable -flake8-tuple -pytest -pytest-cov -pytest-httpbin>=0.0.6 -docutils -wheel -twine diff --git a/setup.py b/setup.py index f9885c00..17c72cd8 100644 --- a/setup.py +++ b/setup.py @@ -4,39 +4,26 @@ import sys import codecs from setuptools import setup, find_packages -from setuptools.command.test import test as TestCommand import httpie - -class PyTest(TestCommand): - """ - Running `$ python setup.py test' simply installs minimal requirements - and runs the tests with no fancy stuff like parallel execution. - - """ - - def finalize_options(self): - TestCommand.finalize_options(self) - self.test_args = [ - '--doctest-modules', - '--verbose', - './httpie', - './tests', - ] - self.test_suite = True - - def run_tests(self): - import pytest - sys.exit(pytest.main(self.test_args)) - - +# Note: keep requirements here to ease distributions packaging tests_require = [ - 'pytest-httpbin', + 'docutils', 'pytest', + 'pytest-httpbin>=0.0.6', +] +dev_require = [ + *tests_require, + 'flake8', + 'flake8-comprehensions', + 'flake8-deprecated', + 'flake8-mutable', + 'flake8-tuple', + 'pytest-cov', + 'twine', + 'wheel', ] - - install_requires = [ 'requests[socks]>=2.22.0', 'Pygments>=2.5.2', @@ -59,6 +46,7 @@ if 'bdist_wheel' not in sys.argv: # bdist_wheel extras_require = { + 'dev': dev_require, 'test': tests_require, # https://wheel.readthedocs.io/en/latest/#defining-conditional-dependencies ':sys_platform == "win32"': install_requires_win_only, @@ -91,8 +79,6 @@ setup( python_requires='>=3.6', extras_require=extras_require, install_requires=install_requires, - tests_require=tests_require, - cmdclass={'test': PyTest}, classifiers=[ 'Development Status :: 5 - Production/Stable', 'Programming Language :: Python',