Skip to content

Commit 987ab7f

Browse files
authored
Add pytest ordering and check formatter uniqueness failure (#47)
1 parent ee482f1 commit 987ab7f

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
markers =
3+
last: run marked tests after all others

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dev =
4343
pytest-cov
4444
test =
4545
pytest>=7.2
46+
pytest-ordering
4647

4748
[options.packages.find]
4849
where = src

tests/test_dateformat/test_base.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,24 @@ def test_formatters_are_unique(self):
2020
BaseDateFormat.__subclasses__()
2121
), "Formatter names have to be unique."
2222

23-
# TODO: order tests, so this test is run last; otherwise formatter names won't be unique
24-
# class ISO8601DateFormat2(BaseDateFormat):
25-
# # NOTE: do we care about validation? could use regex
26-
# # but maybe be permissive, warn if invalid but we can parse
27-
28-
# name = "ISO8601"
29-
30-
# assert len(BaseDateFormat.available_formatters()) != len(BaseDateFormat.__subclasses__())
31-
3223
def test_parse_not_implemented(self):
3324
with pytest.raises(NotImplementedError):
3425
BaseDateFormat().parse("foo bar baz")
3526

3627
def test_parse_to_string(self):
3728
with pytest.raises(NotImplementedError):
3829
BaseDateFormat().to_string(1991)
30+
31+
32+
@pytest.mark.last
33+
def test_formatters_unique_error():
34+
# confirm that our uniqe formatters check fails when it should
35+
36+
# run this test last because we can't undefine the subclass
37+
# once it exists...
38+
class ISO8601DateFormat2(BaseDateFormat):
39+
name = "ISO8601" # duplicates existing formatter
40+
41+
assert len(BaseDateFormat.available_formatters()) != len(
42+
BaseDateFormat.__subclasses__()
43+
)

0 commit comments

Comments
 (0)