Unrud 3 лет назад
Родитель
Сommit
413c74c27c
4 измененных файлов с 17 добавлено и 20 удалено
  1. 1 1
      .github/workflows/test.yml
  2. 9 0
      conftest.py
  3. 3 5
      setup.cfg
  4. 4 14
      setup.py

+ 1 - 1
.github/workflows/test.yml

@@ -21,7 +21,7 @@ jobs:
       - name: Install from source
         run: python -m pip install --editable .[test,bcrypt]
       - name: Run tests
-        run: python setup.py test
+        run: python -m pytest
       - name: Upload coverage to Coveralls
         if: github.event_name == 'push'
         env:

+ 9 - 0
conftest.py

@@ -0,0 +1,9 @@
+import sys
+from importlib.util import find_spec
+
+
+def pytest_addoption(parser, pluginmanager):
+    # Ignore the "--mypy" argument if pytest-mypy is not installed and
+    # the implementation is not cpython
+    if sys.implementation.name != 'cpython' and not find_spec("pytest_mypy"):
+        parser.addoption("--mypy", action="store_true")

+ 3 - 5
setup.cfg

@@ -1,12 +1,10 @@
-[aliases]
-test = pytest
-
 [bdist_wheel]
 python-tag = py3
 
 [tool:pytest]
-# More options are set in `setup.py` via environment variable `PYTEST_ADDOPTS`
-addopts = --flake8 --isort --typeguard-packages=radicale --cov --cov-report=term --cov-report=xml -r s
+# The "--mypy" argument is ignored in conftest.py if pytest-mypy is not
+# installed and the implementation is not cpython
+addopts = --flake8 --isort --typeguard-packages=radicale --mypy --cov --cov-report=term --cov-report=xml -r s
 norecursedirs = dist .cache .git build Radicale.egg-info .eggs venv
 
 [tool:isort]

+ 4 - 14
setup.py

@@ -36,9 +36,6 @@ For further information, please visit the `Radicale Website
 
 """
 
-import os
-import sys
-
 from setuptools import find_packages, setup
 
 # When the version is updated, a new section in the CHANGELOG.md file must be
@@ -52,16 +49,10 @@ WEB_FILES = ["web/internal_data/css/icon.png",
 install_requires = ["defusedxml", "passlib", "vobject>=0.9.6",
                     "python-dateutil>=2.7.3",
                     "setuptools; python_version<'3.9'"]
-setup_requires = []
-if {"pytest", "test", "ptr"}.intersection(sys.argv):
-    setup_requires.append("pytest-runner")
-tests_require = ["pytest-runner", "pytest<7", "pytest-cov", "pytest-flake8",
-                 "pytest-isort", "typeguard", "waitress"]
-os.environ["PYTEST_ADDOPTS"] = os.environ.get("PYTEST_ADDOPTS", "")
-# Mypy only supports CPython
-if sys.implementation.name == "cpython":
-    tests_require.extend(["pytest-mypy", "types-setuptools"])
-    os.environ["PYTEST_ADDOPTS"] += " --mypy"
+tests_require = ["pytest", "pytest-cov", "pytest-flake8", "pytest-isort",
+                 "typeguard", "waitress",
+                 "pytest-mypy; implementation_name=='cpython'",
+                 "types-setuptools; implementation_name=='cpython'"]
 
 setup(
     name="Radicale",
@@ -80,7 +71,6 @@ setup(
     package_data={"radicale": [*WEB_FILES, "py.typed"]},
     entry_points={"console_scripts": ["radicale = radicale.__main__:run"]},
     install_requires=install_requires,
-    setup_requires=setup_requires,
     tests_require=tests_require,
     extras_require={"test": tests_require,
                     "bcrypt": ["passlib[bcrypt]", "bcrypt"]},