diff --git a/pylib/Makefile b/pylib/Makefile index 978cabd3b..c7d56fd62 100644 --- a/pylib/Makefile +++ b/pylib/Makefile @@ -55,7 +55,7 @@ CHECKDEPS := $(shell find anki tests -name '*.py' | grep -v buildhash.py) @touch $@ .build/test: $(CHECKDEPS) - python -m nose2 --plugin=nose2.plugins.mp -N 16 + python -m pytest @touch $@ .build/lint: $(CHECKDEPS) diff --git a/pylib/requirements.dev b/pylib/requirements.dev index b23c2314e..49b03ef69 100644 --- a/pylib/requirements.dev +++ b/pylib/requirements.dev @@ -2,7 +2,7 @@ wheel mypy mypy_protobuf black -nose2 +pytest # fixme: when isort 5.0 is released, switch to pypi git+https://github.com/ankitects/isort#egg=isort # fixme: when pylint supports isort 5.0, switch to pypi diff --git a/pylib/tests/test_exporting.py b/pylib/tests/test_exporting.py index bb691254f..1ab6b1ee1 100644 --- a/pylib/tests/test_exporting.py +++ b/pylib/tests/test_exporting.py @@ -3,8 +3,6 @@ import os import tempfile -from nose2.tools.decorators import with_setup - from anki import Collection as aopen from anki.exporting import * from anki.importing import Anki2Importer @@ -41,8 +39,8 @@ def setup1(): ########################################################################## -@with_setup(setup1) def test_export_anki(): + setup1() # create a new deck with its own conf to test conf copying did = deck.decks.id("test") dobj = deck.decks.get(did) @@ -83,8 +81,8 @@ def test_export_anki(): assert d2.cardCount() == 1 -@with_setup(setup1) def test_export_ankipkg(): + setup1() # add a test file to the media folder with open(os.path.join(deck.media.dir(), "今日.mp3"), "w") as f: f.write("test") @@ -99,8 +97,8 @@ def test_export_ankipkg(): e.exportInto(newname) -@with_setup(setup1) def test_export_anki_due(): + setup1() deck = getEmptyCol() f = deck.newNote() f["Front"] = "foo" @@ -132,8 +130,8 @@ def test_export_anki_due(): assert c.due - deck2.sched.today == 1 -# @with_setup(setup1) # def test_export_textcard(): +# setup1() # e = TextCardExporter(deck) # f = unicode(tempfile.mkstemp(prefix="ankitest")[1]) # os.unlink(f) @@ -142,8 +140,8 @@ def test_export_anki_due(): # e.exportInto(f) -@with_setup(setup1) def test_export_textnote(): + setup1() e = TextNoteExporter(deck) fd, f = tempfile.mkstemp(prefix="ankitest") f = str(f) diff --git a/pylib/tests/test_find.py b/pylib/tests/test_find.py index f1a79edee..e7dc215de 100644 --- a/pylib/tests/test_find.py +++ b/pylib/tests/test_find.py @@ -1,5 +1,5 @@ # coding: utf-8 -from nose2.tools.such import helper +import pytest from anki.find import Finder from tests.shared import getEmptyCol @@ -111,7 +111,7 @@ def test_findCards(): assert len(deck.findCards("nid:%d" % f.id)) == 2 assert len(deck.findCards("nid:%d,%d" % (f1id, f2id))) == 2 # templates - with helper.assertRaises(Exception): + with pytest.raises(Exception): deck.findCards("card:foo") assert len(deck.findCards("'card:card 1'")) == 4 assert len(deck.findCards("card:reverse")) == 1 @@ -147,7 +147,7 @@ def test_findCards(): assert len(deck.findCards("-deck:foo")) == 5 assert len(deck.findCards("deck:def*")) == 5 assert len(deck.findCards("deck:*EFAULT")) == 5 - with helper.assertRaises(Exception): + with pytest.raises(Exception): deck.findCards("deck:*cefault") # full search f = deck.newNote() @@ -164,7 +164,7 @@ def test_findCards(): # assert len(deck.findCards("helloworld", full=True)) == 2 # assert len(deck.findCards("back:helloworld", full=True)) == 2 # searching for an invalid special tag should not error - with helper.assertRaises(Exception): + with pytest.raises(Exception): len(deck.findCards("is:invalid")) # should be able to limit to parent deck, no children id = deck.db.scalar("select id from cards limit 1") @@ -238,9 +238,9 @@ def test_findCards(): assert len(deck.findCards("added:1")) == deck.cardCount() - 1 assert len(deck.findCards("added:2")) == deck.cardCount() # flag - with helper.assertRaises(Exception): + with pytest.raises(Exception): deck.findCards("flag:01") - with helper.assertRaises(Exception): + with pytest.raises(Exception): deck.findCards("flag:12") diff --git a/qt/Makefile b/qt/Makefile index 90e355d5a..149a0d129 100644 --- a/qt/Makefile +++ b/qt/Makefile @@ -75,7 +75,7 @@ CHECKDEPS := $(shell find aqt tests -name '*.py') @touch $@ .build/test: $(CHECKDEPS) - python -m nose2 --plugin=nose2.plugins.mp -N 16 + python -m pytest @touch $@ .build/lint: $(CHECKDEPS) diff --git a/qt/tests/test_addons.py b/qt/tests/test_addons.py index c5708842c..f13aefe1c 100644 --- a/qt/tests/test_addons.py +++ b/qt/tests/test_addons.py @@ -3,7 +3,6 @@ from tempfile import TemporaryDirectory from zipfile import ZipFile from mock import MagicMock -from nose2.tools.such import helper from aqt.addons import AddonManager @@ -64,4 +63,4 @@ def assertReadManifest(contents, expectedManifest, nameInZip="manifest.json"): adm = AddonManager(MagicMock()) with ZipFile(zfn, "r") as zfile: - helper.assertEquals(adm.readManifestFile(zfile), expectedManifest) + assert adm.readManifestFile(zfile) == expectedManifest diff --git a/qt/tools/tests.sh b/qt/tools/tests.sh deleted file mode 100755 index 40c8f8b27..000000000 --- a/qt/tools/tests.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -# -# Usage: -# tools/tests.sh # run all tests -# tools/tests.sh decks # test only test_decks.py -# coverage=1 tools/tests.sh # run with coverage test - -set -e - -BIN="$(cd "`dirname "$0"`"; pwd)" -export PYTHONPATH=${BIN}/..:${PYTHONPATH} - -nose="python -m nose2 --plugin=nose2.plugins.mp -N 16" - -dir=. - -if [ x$1 = x ]; then - lim="tests" -else - lim="tests.test_$1" -fi - -(cd $dir && $nose $lim $args)