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]'
This commit is contained in:
Mickaël Schoentgen 2021-06-11 20:55:26 +02:00 committed by GitHub
parent da03a0656e
commit 9857693ebf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 46 deletions

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -1,11 +0,0 @@
flake8
flake8-comprehensions
flake8-deprecated
flake8-mutable
flake8-tuple
pytest
pytest-cov
pytest-httpbin>=0.0.6
docutils
wheel
twine

View File

@ -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',