From 799cdafae63b3ac22aafed4400bff10796a8ffee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastien=20G=C3=A9rard?= Date: Sun, 1 Sep 2019 15:27:11 +0300 Subject: [PATCH] remove references to nose --- CONTRIBUTING.rst | 2 +- requirements.txt | 1 - setup.py | 2 +- tests/document/test_indexes.py | 3 +-- tests/fields/test_email_field.py | 6 ------ tests/fields/test_fields.py | 13 ++++++------- tests/fields/test_file_field.py | 29 +++++++++-------------------- tests/test_connection.py | 31 +++++++++++++++---------------- tests/utils.py | 10 ++++------ tox.ini | 1 - 10 files changed, 37 insertions(+), 61 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 4711c1d3..56bae31f 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -54,7 +54,7 @@ General Guidelines should adapt to the breaking change in docs/upgrade.rst. - Write inline documentation for new classes and methods. - Write tests and make sure they pass (make sure you have a mongod - running on the default port, then execute ``python setup.py nosetests`` + running on the default port, then execute ``python setup.py test`` from the cmd line to run the test suite). - Ensure tests pass on all supported Python, PyMongo, and MongoDB versions. You can test various Python and PyMongo versions locally by executing diff --git a/requirements.txt b/requirements.txt index 46eabac3..43e5261b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -nose pymongo>=3.4 six==1.10.0 Sphinx==1.5.5 diff --git a/setup.py b/setup.py index 2bc1ae1c..939e8e50 100644 --- a/setup.py +++ b/setup.py @@ -120,7 +120,7 @@ extra_opts = { } if sys.version_info[0] == 3: extra_opts["use_2to3"] = True - if "test" in sys.argv or "nosetests" in sys.argv: + if "test" in sys.argv: extra_opts["packages"] = find_packages() extra_opts["package_data"] = { "tests": ["fields/mongoengine.png", "fields/mongodb_leaf.png"] diff --git a/tests/document/test_indexes.py b/tests/document/test_indexes.py index dc6c5c8e..90402c46 100644 --- a/tests/document/test_indexes.py +++ b/tests/document/test_indexes.py @@ -2,7 +2,6 @@ import unittest from datetime import datetime -from nose.plugins.skip import SkipTest from pymongo.collation import Collation from pymongo.errors import OperationFailure import pytest @@ -251,7 +250,7 @@ class TestIndexes(unittest.TestCase): def test_explicit_geohaystack_index(self): """Ensure that geohaystack indexes work when created via meta[indexes] """ - raise SkipTest( + pytest.skip( "GeoHaystack index creation is not supported for now" "from meta, as it requires a bucketSize parameter." ) diff --git a/tests/fields/test_email_field.py b/tests/fields/test_email_field.py index 55255df5..5a58ede4 100644 --- a/tests/fields/test_email_field.py +++ b/tests/fields/test_email_field.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import sys -from unittest import SkipTest import pytest @@ -46,11 +45,6 @@ class TestEmailField(MongoDBTestCase): user.validate() def test_email_field_unicode_user(self): - # Don't run this test on pypy3, which doesn't support unicode regex: - # https://bitbucket.org/pypy/pypy/issues/1821/regular-expression-doesnt-find-unicode - if sys.version_info[:2] == (3, 2): - raise SkipTest("unicode email addresses are not supported on PyPy 3") - class User(Document): email = EmailField() diff --git a/tests/fields/test_fields.py b/tests/fields/test_fields.py index b8c916f8..652f6903 100644 --- a/tests/fields/test_fields.py +++ b/tests/fields/test_fields.py @@ -3,7 +3,6 @@ import datetime import unittest from bson import DBRef, ObjectId, SON -from nose.plugins.skip import SkipTest import pytest from mongoengine import ( @@ -1239,17 +1238,17 @@ class TestField(MongoDBTestCase): a = A._from_son(SON([("fb", SON([("fc", SON([("txt", "hi")]))]))])) assert a.b.c.txt == "hi" + @pytest.mark.xfail( + reason="Using a string reference in an EmbeddedDocumentField does not work if the class isnt registerd yet", + raises=NotRegistered, + ) def test_embedded_document_field_cant_reference_using_a_str_if_it_does_not_exist_yet( self, ): - raise SkipTest( - "Using a string reference in an EmbeddedDocumentField does not work if the class isnt registerd yet" - ) - class MyDoc2(Document): - emb = EmbeddedDocumentField("MyDoc") + emb = EmbeddedDocumentField("MyFunkyDoc123") - class MyDoc(EmbeddedDocument): + class MyFunkyDoc123(EmbeddedDocument): name = StringField() def test_embedded_document_validation(self): diff --git a/tests/fields/test_file_field.py b/tests/fields/test_file_field.py index fb8cacff..bfc86511 100644 --- a/tests/fields/test_file_field.py +++ b/tests/fields/test_file_field.py @@ -5,7 +5,7 @@ import tempfile import unittest import gridfs -from nose.plugins.skip import SkipTest +import pytest import six from mongoengine import * @@ -21,6 +21,8 @@ except ImportError: from tests.utils import MongoDBTestCase +require_pil = pytest.mark.skipif(not HAS_PIL, reason="PIL not installed") + TEST_IMAGE_PATH = os.path.join(os.path.dirname(__file__), "mongoengine.png") TEST_IMAGE2_PATH = os.path.join(os.path.dirname(__file__), "mongodb_leaf.png") @@ -377,10 +379,8 @@ class TestFileField(MongoDBTestCase): assert len(list(files)) == 0 assert len(list(chunks)) == 0 + @require_pil def test_image_field(self): - if not HAS_PIL: - raise SkipTest("PIL not installed") - class TestImage(Document): image = ImageField() @@ -411,10 +411,8 @@ class TestFileField(MongoDBTestCase): t.image.delete() + @require_pil def test_image_field_reassigning(self): - if not HAS_PIL: - raise SkipTest("PIL not installed") - class TestFile(Document): the_file = ImageField() @@ -428,10 +426,8 @@ class TestFileField(MongoDBTestCase): test_file.save() assert test_file.the_file.size == (45, 101) + @require_pil def test_image_field_resize(self): - if not HAS_PIL: - raise SkipTest("PIL not installed") - class TestImage(Document): image = ImageField(size=(185, 37)) @@ -451,10 +447,8 @@ class TestFileField(MongoDBTestCase): t.image.delete() + @require_pil def test_image_field_resize_force(self): - if not HAS_PIL: - raise SkipTest("PIL not installed") - class TestImage(Document): image = ImageField(size=(185, 37, True)) @@ -474,10 +468,8 @@ class TestFileField(MongoDBTestCase): t.image.delete() + @require_pil def test_image_field_thumbnail(self): - if not HAS_PIL: - raise SkipTest("PIL not installed") - class TestImage(Document): image = ImageField(thumbnail_size=(92, 18)) @@ -546,11 +538,8 @@ class TestFileField(MongoDBTestCase): assert putfile == copy.copy(putfile) assert putfile == copy.deepcopy(putfile) + @require_pil def test_get_image_by_grid_id(self): - - if not HAS_PIL: - raise SkipTest("PIL not installed") - class TestImage(Document): image1 = ImageField() diff --git a/tests/test_connection.py b/tests/test_connection.py index 07edcbba..acaab904 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -1,7 +1,6 @@ import datetime from bson.tz_util import utc -from nose.plugins.skip import SkipTest import pymongo from pymongo import MongoClient, ReadPreference @@ -35,6 +34,18 @@ def get_tz_awareness(connection): return connection.codec_options.tz_aware +try: + import mongomock + + MONGOMOCK_INSTALLED = True +except ImportError: + MONGOMOCK_INSTALLED = False + +require_mongomock = pytest.mark.skipif( + not MONGOMOCK_INSTALLED, reason="you need mongomock installed to run this testcase" +) + + class ConnectionTest(unittest.TestCase): @classmethod def setUpClass(cls): @@ -212,14 +223,10 @@ class ConnectionTest(unittest.TestCase): non_string_db_name = ["e. g. list instead of a string"] connect(non_string_db_name) + @require_mongomock def test_connect_in_mocking(self): """Ensure that the connect() method works properly in mocking. """ - try: - import mongomock - except ImportError: - raise SkipTest("you need mongomock installed to run this testcase") - connect("mongoenginetest", host="mongomock://localhost") conn = get_connection() assert isinstance(conn, mongomock.MongoClient) @@ -261,14 +268,10 @@ class ConnectionTest(unittest.TestCase): conn = get_connection("testdb7") assert isinstance(conn, mongomock.MongoClient) + @require_mongomock def test_default_database_with_mocking(self): """Ensure that the default database is correctly set when using mongomock. """ - try: - import mongomock - except ImportError: - raise SkipTest("you need mongomock installed to run this testcase") - disconnect_all() class SomeDocument(Document): @@ -281,16 +284,12 @@ class ConnectionTest(unittest.TestCase): assert conn.get_default_database().name == "mongoenginetest" assert conn.database_names()[0] == "mongoenginetest" + @require_mongomock def test_connect_with_host_list(self): """Ensure that the connect() method works when host is a list Uses mongomock to test w/o needing multiple mongod/mongos processes """ - try: - import mongomock - except ImportError: - raise SkipTest("you need mongomock installed to run this testcase") - connect(host=["mongomock://localhost"]) conn = get_connection() assert isinstance(conn, mongomock.MongoClient) diff --git a/tests/utils.py b/tests/utils.py index 0719d6ef..7ee22c3c 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,7 +1,6 @@ -import operator import unittest -from nose.plugins.skip import SkipTest +import pytest from mongoengine import connect from mongoengine.connection import disconnect_all, get_db @@ -37,7 +36,7 @@ def get_as_pymongo(doc): def _decorated_with_ver_requirement(func, mongo_version_req, oper): """Return a MongoDB version requirement decorator. - The resulting decorator will raise a SkipTest exception if the current + The resulting decorator will skip the test if the current MongoDB version doesn't match the provided version/operator. For example, if you define a decorator like so: @@ -59,9 +58,8 @@ def _decorated_with_ver_requirement(func, mongo_version_req, oper): if oper(mongodb_v, mongo_version_req): return func(*args, **kwargs) - raise SkipTest( - "Needs MongoDB v{}+".format(".".join(str(n) for n in mongo_version_req)) - ) + pretty_version = ".".join(str(n) for n in mongo_version_req) + pytest.skip("Needs MongoDB v{}+".format(pretty_version)) _inner.__name__ = func.__name__ _inner.__doc__ = func.__doc__ diff --git a/tox.ini b/tox.ini index 94ccc9cf..349b5577 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,6 @@ envlist = {py27,py35,pypy,pypy3}-{mg34,mg36} commands = python setup.py test {posargs} deps = - nose mg34: pymongo>=3.4,<3.5 mg36: pymongo>=3.6,<3.7 mg39: pymongo>=3.9,<4.0