From 8f0c8b6f8a4ac9c5e79612ae79c8f99775763d34 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 1 Mar 2021 12:47:39 +1000 Subject: [PATCH] use different approach to running tests twice The symlink approach was breaking on Windows --- pylib/tests/test_sched2021.py | 5 ++++- pylib/tests/test_schedv2.py | 25 +++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) mode change 120000 => 100644 pylib/tests/test_sched2021.py diff --git a/pylib/tests/test_sched2021.py b/pylib/tests/test_sched2021.py deleted file mode 120000 index e0aedf8f1..000000000 --- a/pylib/tests/test_sched2021.py +++ /dev/null @@ -1 +0,0 @@ -test_schedv2.py \ No newline at end of file diff --git a/pylib/tests/test_sched2021.py b/pylib/tests/test_sched2021.py new file mode 100644 index 000000000..5d698d2ce --- /dev/null +++ b/pylib/tests/test_sched2021.py @@ -0,0 +1,4 @@ +# Copyright: Ankitects Pty Ltd and contributors +# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +from .test_schedv2 import * diff --git a/pylib/tests/test_schedv2.py b/pylib/tests/test_schedv2.py index bf84a8834..09738bacb 100644 --- a/pylib/tests/test_schedv2.py +++ b/pylib/tests/test_schedv2.py @@ -1,6 +1,7 @@ # coding: utf-8 import copy +import os import time from typing import Tuple @@ -13,18 +14,18 @@ from anki.schedv2 import UnburyCurrentDeck from anki.utils import intTime from tests.shared import getEmptyCol as getEmptyColOrig + # This file is used to exercise both the legacy Python 2.1 scheduler, # and the experimental new one in Rust. Most tests run on both, but a few # tests have been implemented separately where the behaviour differs. -is_2021 = "2021" in __file__ -new_sched_only = pytest.mark.skipif(not is_2021, reason="2021 only") -old_sched_only = pytest.mark.skipif(is_2021, reason="old only") +def is_2021() -> bool: + return "2021" in os.getenv("PYTEST_CURRENT_TEST") def getEmptyCol(): col = getEmptyColOrig() col.upgrade_to_v2_scheduler() - if is_2021: + if is_2021(): col.set_2021_test_scheduler_enabled(True) return col @@ -315,7 +316,7 @@ def test_learn_day(): c.due -= 1 c.flush() col.reset() - if is_2021: + if is_2021(): # it appears in the review queue assert col.sched.counts() == (0, 0, 1) else: @@ -468,8 +469,9 @@ def review_limits_setup() -> Tuple[anki.collection.Collection, Dict]: return col, child -@old_sched_only def test_review_limits(): + if is_2021(): + pytest.skip("old sched only") col, child = review_limits_setup() tree = col.sched.deck_due_tree().children @@ -492,8 +494,9 @@ def test_review_limits(): assert tree[0].children[0].review_count == 9 # child -@new_sched_only def test_review_limits_new(): + if not is_2021(): + pytest.skip("new sched only") col, child = review_limits_setup() tree = col.sched.deck_due_tree().children @@ -917,8 +920,9 @@ def test_ordcycle(): col.sched.answerCard(c, 4) -@old_sched_only def test_counts_idx(): + if is_2021(): + pytest.skip("old sched only") col = getEmptyCol() note = col.newNote() note["Front"] = "one" @@ -942,8 +946,9 @@ def test_counts_idx(): assert col.sched.counts() == (0, 1, 0) -@new_sched_only def test_counts_idx_new(): + if not is_2021(): + pytest.skip("new sched only") col = getEmptyCol() note = col.newNote() note["Front"] = "one" @@ -1154,7 +1159,7 @@ def test_deckFlow(): col.addNote(note) col.reset() assert col.sched.counts() == (3, 0, 0) - if is_2021: + if is_2021(): # cards arrive in position order by default for i in "one", "two", "three": c = col.sched.getCard()