Skip to content

Commit 9e3f1d9

Browse files
authored
Merge pull request #2804 from bagerard/remove_setup_py_test
Remove 'python setup.py test' usage in tox
2 parents ce9e108 + bd58f95 commit 9e3f1d9

13 files changed

+43
-126
lines changed

.github/workflows/github-actions.yml

+6-6
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:
@@ -91,9 +91,9 @@ jobs:
9191
bash .github/workflows/install_ci_python_dep.sh
9292
bash .github/workflows/start_mongo.sh ${{ matrix.MONGODB }}
9393
- name: tox dry-run (to pre-install venv)
94-
run: tox -e $(echo py${{ matrix.python-version }}-mg${{ matrix.PYMONGO }} | tr -d . | sed -e 's/pypypy/pypy/') -- -a "-k=test_ci_placeholder"
94+
run: tox -e $(echo py${{ matrix.python-version }}-mg${{ matrix.PYMONGO }} | tr -d . | sed -e 's/pypypy/pypy/') -- "-k=test_ci_placeholder"
9595
- name: Run test suite
96-
run: tox -e $(echo py${{ matrix.python-version }}-mg${{ matrix.PYMONGO }} | tr -d . | sed -e 's/pypypy/pypy/') -- -a "--cov=mongoengine"
96+
run: tox -e $(echo py${{ matrix.python-version }}-mg${{ matrix.PYMONGO }} | tr -d . | sed -e 's/pypypy/pypy/') -- "--cov=mongoengine"
9797
- name: Send coverage to Coveralls
9898
env:
9999
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.pre-commit-config.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
fail_fast: false
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.4.0
4+
rev: v4.5.0
55
hooks:
66
- id: check-merge-conflict
77
- id: debug-statements
88
- id: trailing-whitespace
99
- id: end-of-file-fixer
1010
- repo: https://github.com/ambv/black
11-
rev: 23.9.1
11+
rev: 24.2.0
1212
hooks:
1313
- id: black
1414
- repo: https://github.com/pycqa/flake8
15-
rev: 6.1.0
15+
rev: 7.0.0
1616
hooks:
1717
- id: flake8
1818
additional_dependencies:
1919
- importlib_metadata<5
2020
- repo: https://github.com/asottile/pyupgrade
21-
rev: v3.14.0
21+
rev: v3.15.1
2222
hooks:
2323
- id: pyupgrade
2424
args: [--py36-plus]
2525
- repo: https://github.com/pycqa/isort
26-
rev: 5.12.0
26+
rev: 5.13.2
2727
hooks:
2828
- id: isort

CONTRIBUTING.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ General Guidelines
8282
should adapt to the breaking change in docs/upgrade.rst.
8383
- Write inline documentation for new classes and methods.
8484
- Write tests and make sure they pass (make sure you have a mongod
85-
running on the default port, then execute ``python setup.py test``
85+
running on the default port, then execute ``pytest tests/``
8686
from the cmd line to run the test suite).
8787
- Ensure tests pass on all supported Python, PyMongo, and MongoDB versions.
8888
You can test various Python and PyMongo versions locally by executing

README.rst

+1-11
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ Some simple examples of what MongoEngine code looks like:
125125
Tests
126126
=====
127127
To run the test suite, ensure you are running a local instance of MongoDB on
128-
the standard port and have ``pytest`` installed. Then, run ``python setup.py test``
129-
or simply ``pytest``.
128+
the standard port and have ``pytest`` installed. Then, run ``pytest tests/``.
130129

131130
To run the test suite on every supported Python and PyMongo version, you can
132131
use ``tox``. You'll need to make sure you have each supported Python version
@@ -139,15 +138,6 @@ installed in your environment and then:
139138
# Run the test suites
140139
$ tox
141140
142-
If you wish to run a subset of tests, use the pytest convention:
143-
144-
.. code-block:: shell
145-
146-
# Run all the tests in a particular test file
147-
$ pytest tests/fields/test_fields.py
148-
# Run only particular test class in that file
149-
$ pytest tests/fields/test_fields.py::TestField
150-
151141
Community
152142
=========
153143
- `MongoEngine Users mailing list

benchmarks/test_basic_doc_ops.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,9 @@ def save_book():
6060
print("Save to database: %.3fus" % (timeit(save_book, 100) * 10**6))
6161

6262
son = b.to_mongo()
63-
print(
64-
"Load from SON: %.3fus" % (timeit(lambda: Book._from_son(son), 1000) * 10**6)
65-
)
63+
print("Load from SON: %.3fus" % (timeit(lambda: Book._from_son(son), 1000) * 10**6))
6664

67-
print(
68-
"Load from database: %.3fus" % (timeit(lambda: Book.objects[0], 100) * 10**6)
69-
)
65+
print("Load from database: %.3fus" % (timeit(lambda: Book.objects[0], 100) * 10**6))
7066

7167
def create_and_delete_book():
7268
b = init_book()
@@ -116,13 +112,11 @@ def save_company():
116112

117113
son = company.to_mongo()
118114
print(
119-
"Load from SON: %.3fms"
120-
% (timeit(lambda: Company._from_son(son), 100) * 10**3)
115+
"Load from SON: %.3fms" % (timeit(lambda: Company._from_son(son), 100) * 10**3)
121116
)
122117

123118
print(
124-
"Load from database: %.3fms"
125-
% (timeit(lambda: Company.objects[0], 100) * 10**3)
119+
"Load from database: %.3fms" % (timeit(lambda: Company.objects[0], 100) * 10**3)
126120
)
127121

128122
def create_and_delete_company():

docs/changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Changelog
77
Development
88
===========
99
- (Fill this out as you fix issues and develop your features).
10+
- Switch tox to use pytest instead of legacy `python setup.py test` #2804
1011

1112
Changes in 0.28.2
1213
=================

mongoengine/mongodb_support.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Helper functions, constants, and types to aid with MongoDB version support
33
"""
4+
45
from mongoengine.connection import get_connection
56

67
# Constant that can be used to compare the version retrieved with

mongoengine/pymongo_support.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Helper functions, constants, and types to aid with PyMongo support.
33
"""
4+
45
import pymongo
56
from bson import binary, json_util
67
from pymongo.errors import OperationFailure

mongoengine/signals.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def _fail(self, *args, **kwargs):
3838
)
3939

4040
send = lambda *a, **kw: None # noqa
41-
connect = (
42-
disconnect
43-
) = has_receivers_for = receivers_for = temporarily_connected_to = _fail
41+
connect = disconnect = has_receivers_for = receivers_for = (
42+
temporarily_connected_to
43+
) = _fail
4444
del _fail
4545

4646

requirements-dev.txt

+1-3
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

+13-84
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
)

tests/all_warnings/test_warnings.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
only get triggered on first hit. This way we can ensure its imported into the
44
top level and called first by the test suite.
55
"""
6+
67
import unittest
78
import warnings
89

tox.ini

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
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
1113
mg4: pymongo>=4.0,<4.1
12-
mg432: pymongo>=4.3,<4.4
14+
mg433: pymongo>=4.3,<4.4
1315
mg441: pymongo>=4.4,<4.5
14-
mg460: pymongo>=4.6,<4.7
16+
mg462: pymongo>=4.6,<4.7
1517
setenv =
1618
PYTHON_EGG_CACHE = {envdir}/python-eggs

0 commit comments

Comments
 (0)