Skip to content

Commit 9e3b48e

Browse files
committed
Remove 'python setup.py test' usage in tox
1 parent ce9e108 commit 9e3b48e

File tree

4 files changed

+22
-93
lines changed

4 files changed

+22
-93
lines changed

.github/workflows/github-actions.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ env:
2626
PYMONGO_3_11: 3.11
2727
PYMONGO_3_12: 3.12
2828
PYMONGO_4_0: 4.0
29-
PYMONGO_4_3: 4.3.2
29+
PYMONGO_4_3: 4.3.3
3030
PYMONGO_4_4: 4.4.1
31-
PYMONGO_4_6: 4.6.0
31+
PYMONGO_4_6: 4.6.2
3232

33-
MAIN_PYTHON_VERSION: 3.7
33+
MAIN_PYTHON_VERSION: 3.9
3434

3535
jobs:
3636
linting:
@@ -53,7 +53,7 @@ jobs:
5353
strategy:
5454
fail-fast: false
5555
matrix:
56-
python-version: [3.7, 3.8, 3.9, "3.10", 3.11, "pypy3.9"]
56+
python-version: [3.7, 3.8, 3.9, "3.10", 3.11, pypy3.9, pypy3.10]
5757
MONGODB: [$MONGODB_4_0]
5858
PYMONGO: [$PYMONGO_3_11]
5959
include:
@@ -110,7 +110,7 @@ jobs:
110110
- name: Set up Python ${{ matrix.python-version }}
111111
uses: actions/setup-python@v4
112112
with:
113-
python-version: 3.7
113+
python-version: 3.9
114114
check-latest: true
115115
- name: install python dep
116116
run: |

requirements-dev.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
black
2-
flake8
31
pre-commit
4-
pytest
52
ipdb
63
ipython
74
tox
5+
-e .[test]

setup.py

Lines changed: 13 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
import os
2-
import sys
32

4-
from pkg_resources import normalize_path
53
from setuptools import find_packages, setup
6-
from setuptools.command.test import test as TestCommand
7-
8-
# Hack to silence atexit traceback in newer python versions
9-
try:
10-
import multiprocessing # noqa: F401
11-
except ImportError:
12-
pass
134

145
DESCRIPTION = "MongoEngine is a Python Object-Document Mapper for working with MongoDB."
156

@@ -27,62 +18,6 @@ def get_version(version_tuple):
2718
return ".".join(map(str, version_tuple))
2819

2920

30-
class PyTest(TestCommand):
31-
"""Will force pytest to search for tests inside the build directory
32-
for 2to3 converted code (used by tox), instead of the current directory.
33-
Required as long as we need 2to3
34-
35-
Known Limitation: https://tox.readthedocs.io/en/latest/example/pytest.html#known-issues-and-limitations
36-
Source: https://www.hackzine.org/python-testing-with-pytest-and-2to3-plus-tox-and-travis-ci.html
37-
"""
38-
39-
# https://pytest.readthedocs.io/en/2.7.3/goodpractises.html#integration-with-setuptools-test-commands
40-
# Allows to provide pytest command argument through the test runner command `python setup.py test`
41-
# e.g: `python setup.py test -a "-k=test"`
42-
# This only works for 1 argument though
43-
user_options = [("pytest-args=", "a", "Arguments to pass to py.test")]
44-
45-
def initialize_options(self):
46-
TestCommand.initialize_options(self)
47-
self.pytest_args = ""
48-
49-
def finalize_options(self):
50-
TestCommand.finalize_options(self)
51-
self.test_args = ["tests"]
52-
self.test_suite = True
53-
54-
def run_tests(self):
55-
# import here, cause outside the eggs aren't loaded
56-
import pytest
57-
from pkg_resources import _namespace_packages
58-
59-
# Purge modules under test from sys.modules. The test loader will
60-
# re-import them from the build location. Required when 2to3 is used
61-
# with namespace packages.
62-
if sys.version_info >= (3,) and getattr(self.distribution, "use_2to3", False):
63-
module = self.test_args[-1].split(".")[0]
64-
if module in _namespace_packages:
65-
del_modules = []
66-
if module in sys.modules:
67-
del_modules.append(module)
68-
module += "."
69-
for name in sys.modules:
70-
if name.startswith(module):
71-
del_modules.append(name)
72-
map(sys.modules.__delitem__, del_modules)
73-
74-
# Run on the build directory for 2to3-built code
75-
# This will prevent the old 2.x code from being found
76-
# by py.test discovery mechanism, that apparently
77-
# ignores sys.path..
78-
ei_cmd = self.get_finalized_command("egg_info")
79-
self.test_args = [normalize_path(ei_cmd.egg_base)]
80-
81-
cmd_args = self.test_args + ([self.pytest_args] if self.pytest_args else [])
82-
errno = pytest.main(cmd_args)
83-
sys.exit(errno)
84-
85-
8621
# Dirty hack to get version number from monogengine/__init__.py - we can't
8722
# import it as it depends on PyMongo and PyMongo isn't installed until this
8823
# file is read
@@ -107,22 +42,14 @@ def run_tests(self):
10742
"Topic :: Software Development :: Libraries :: Python Modules",
10843
]
10944

110-
extra_opts = {
111-
"packages": find_packages(exclude=["tests", "tests.*"]),
112-
"tests_require": [
113-
"pytest",
114-
"pytest-cov",
115-
"coverage",
116-
"blinker",
117-
"Pillow>=7.0.0",
118-
],
119-
}
120-
121-
if "test" in sys.argv:
122-
extra_opts["packages"] = find_packages()
123-
extra_opts["package_data"] = {
124-
"tests": ["fields/mongoengine.png", "fields/mongodb_leaf.png"]
125-
}
45+
install_require = ["pymongo>=3.4,<5.0"]
46+
tests_require = [
47+
"pytest",
48+
"pytest-cov",
49+
"coverage",
50+
"blinker",
51+
"Pillow>=7.0.0",
52+
]
12653

12754
setup(
12855
name="mongoengine",
@@ -140,7 +67,9 @@ def run_tests(self):
14067
platforms=["any"],
14168
classifiers=CLASSIFIERS,
14269
python_requires=">=3.7",
143-
install_requires=["pymongo>=3.4,<5.0"],
144-
cmdclass={"test": PyTest},
145-
**extra_opts
70+
install_requires=install_require,
71+
extras_require={
72+
"test": tests_require,
73+
},
74+
packages=find_packages(exclude=["tests", "tests.*"]),
14675
)

tox.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
[tox]
22
envlist = pypy3-{mg34,mg36,mg39,mg311,mg312,mg4,mg432,mg441,mg460}
3+
skipsdist = True
34

45
[testenv]
56
commands =
6-
python setup.py test {posargs}
7+
pytest tests/ {posargs}
78
deps =
9+
-rrequirements-dev.txt
810
mg39: pymongo>=3.9,<3.10
911
mg311: pymongo>=3.11,<3.12
1012
mg312: pymongo>=3.12,<3.13

0 commit comments

Comments
 (0)