Skip to content

Commit

Permalink
Fix test order for entities migration (#1566)
Browse files Browse the repository at this point in the history
Replace pytest-ordering with newer pytest-order, stop skipping unit tests in CI
  • Loading branch information
blms committed Apr 2, 2024
1 parent 00f46ea commit 1ebca33
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 42 deletions.
4 changes: 2 additions & 2 deletions geniza/annotations/tests/test_annotations_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from geniza.footnotes.models import Footnote, Source, SourceType


@pytest.mark.second_to_last
@pytest.mark.order("second_to_last")
@pytest.mark.django_db
class TestAssociateRelatedFootnotes(TestMigrations):
app = "annotations"
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_footnote_created(self):
).exists()


@pytest.mark.second_to_last
@pytest.mark.order("second_to_last")
@pytest.mark.django_db
class TestAnnotationCleanupNbsp(TestMigrations):
app = "annotations"
Expand Down
2 changes: 1 addition & 1 deletion geniza/common/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def test_userprofile_str(admin_user):
class TestMigrations(TransactionTestCase):
# Base class for migration test case

# NOTE: subclasses must be marked with @pytest.mark.last
# NOTE: subclasses must be marked with @pytest.mark.order("last")
# to avoid causing errors in fixtures/db state for other tests

app = None
Expand Down
30 changes: 8 additions & 22 deletions geniza/corpus/tests/test_corpus_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from geniza.common.tests import TestMigrations


@pytest.mark.last
@pytest.mark.order("last")
@pytest.mark.django_db
class ReassignLogEntries(TestMigrations):
app = "corpus"
Expand Down Expand Up @@ -42,7 +42,7 @@ def test_log_entries_reassigned(self):
assert self.log_entry.content_type_id == document_type.pk


@pytest.mark.last
@pytest.mark.order("last")
@pytest.mark.django_db
class TestConvertSideToSelectedImages(TestMigrations):
app = "corpus"
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_sides_converted(self):
assert 0 in both_sides.selected_images and 1 in both_sides.selected_images


@pytest.mark.last
@pytest.mark.order("last")
@pytest.mark.django_db
class TestConvertSelectedImagesToSide(TestMigrations):
app = "corpus"
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_sides_converted(self):
assert both_sides.side == "rv"


@pytest.mark.last
@pytest.mark.order("last")
@pytest.mark.django_db
class TestMergeDuplicateTags(TestMigrations):
app = "corpus"
Expand Down Expand Up @@ -217,7 +217,7 @@ def test_tags_merged(self):
).exists()


@pytest.mark.last
@pytest.mark.order("last")
@pytest.mark.django_db
class TestMergeJTSENACollections(TestMigrations):
app = "corpus"
Expand Down Expand Up @@ -264,13 +264,7 @@ def test_merged(self):
assert ena_fragment.collection.pk == self.jts_collection.pk


# the following two tests fail in GitHub Actions with Group.DoesNotExist, but succeed locally;
# possibly related to test order?
@pytest.mark.skipif(
os.getenv("GITHUB_ACTIONS") == "true",
reason="disabled in GitHub Actions due to Group.DoesNotExist in CI only",
)
@pytest.mark.second_to_last
@pytest.mark.order("second_to_last")
@pytest.mark.django_db
class TestDocumentImageOverrides(TestMigrations):
app = "corpus"
Expand All @@ -295,11 +289,7 @@ def test_image_order_to_json(self):
assert order_override.image_overrides["canvas1"]["order"] == 1


@pytest.mark.skipif(
os.getenv("GITHUB_ACTIONS") == "true",
reason="disabled in GitHub Actions due to Group.DoesNotExist in CI only",
)
@pytest.mark.second_to_last
@pytest.mark.order("second_to_last")
@pytest.mark.django_db
class TestDocumentImageOverridesReverse(TestMigrations):
app = "corpus"
Expand All @@ -326,11 +316,7 @@ def test_image_overrides_to_order_array(self):
assert order_override.image_order_override == ["canvas2", "canvas1"]


@pytest.mark.skipif(
os.getenv("GITHUB_ACTIONS") == "true",
reason="disabled in GitHub Actions due to Group.DoesNotExist in CI only",
)
@pytest.mark.second_to_last
@pytest.mark.order("second_to_last")
@pytest.mark.django_db
class TestDocumentCleanupNbsp(TestMigrations):
app = "corpus"
Expand Down
7 changes: 3 additions & 4 deletions geniza/entities/tests/test_entities_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from geniza.common.tests import TestMigrations


@pytest.mark.skipif(
os.getenv("GITHUB_ACTIONS") == "true",
reason="disabled in GitHub Actions due to Group.DoesNotExist in CI only",
# must run before other migrations in order to prevent Group.DoesNotExist
@pytest.mark.order(
before="geniza/annotations/tests/test_annotations_migrations.py::TestAssociateRelatedFootnotes::test_footnote_associated"
)
@pytest.mark.last
@pytest.mark.django_db
class TestPopulatePersonSlugs(TestMigrations):
app = "entities"
Expand Down
12 changes: 6 additions & 6 deletions geniza/footnotes/tests/test_footnotes_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from geniza.common.tests import TestMigrations


@pytest.mark.last
@pytest.mark.order("last")
class MergeIndiaBookSources(TestMigrations):
app = "footnotes"
migrate_from = "0011_split_goitein_typedtexts"
Expand Down Expand Up @@ -36,7 +36,7 @@ def test_sources_merged(self):
assert Footnote.objects.count() == 2


@pytest.mark.last
@pytest.mark.order("last")
class AlterSourceEdition(TestMigrations):
app = "footnotes"
migrate_from = "0013_add_fields_to_source"
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_editions_converted_to_int(self):
assert not self.src3.edition


@pytest.mark.last
@pytest.mark.order("last")
class AlterSourceEditionReverse(TestMigrations):
app = "footnotes"
migrate_from = "0014_alter_source_edition"
Expand All @@ -96,7 +96,7 @@ def test_editions_converted_to_string(self):
assert self.src2.edition == "2"


@pytest.mark.last
@pytest.mark.order("last")
class TestFootnoteLocationPpMigration(TestMigrations):
app = "footnotes"
migrate_from = "0014_alter_source_edition"
Expand Down Expand Up @@ -151,7 +151,7 @@ def test_locations_prefixed_pp(self):
assert Footnote.objects.filter(location=page_loc).exists()


@pytest.mark.last
@pytest.mark.order("last")
class TestRenameTypedTextsMigration(TestMigrations):
app = "footnotes"
migrate_from = "0015_add_footnote_location_pp"
Expand Down Expand Up @@ -196,7 +196,7 @@ def test_rename_typed_texts(self):
)


@pytest.mark.last
@pytest.mark.order("last")
@pytest.mark.django_db
class TestDigitalFootnoteLocation(TestMigrations):
app = "footnotes"
Expand Down
9 changes: 3 additions & 6 deletions geniza/pages/tests/test_pages_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
RAW_TEXT = "<h2>Geniza Project contributors</h2><h3>Co-PI Research Lead</h3><p><b>Marina Rustow</b></p<h3>Co-PI Technical Lead</h3><p>Rebecca Sutton Koeser</p><blockquote>Project Manager (March 2020-Present)</blockquote><blockquote>Rachel Richman</blockquote>"


@pytest.mark.last
@pytest.mark.order("last")
@pytest.mark.django_db
class TestConvertFieldsToStreamField(TestMigrations):

app = "pages"
migrate_from = "0005_containerpage"
migrate_to = "0006_convert_richtextfield_to_streamfield"
Expand Down Expand Up @@ -77,10 +76,9 @@ def test_revision_converted(self):
assert isinstance(body_data, list)


@pytest.mark.last
@pytest.mark.order("last")
@pytest.mark.django_db
class TestConvertFieldsReverseToRichTextField(TestMigrations):

app = "pages"
migrate_from = "0006_convert_richtextfield_to_streamfield"
migrate_to = "0005_containerpage"
Expand Down Expand Up @@ -138,10 +136,9 @@ def test_revision_converted(self):
assert isinstance(body, str)


@pytest.mark.last
@pytest.mark.order("last")
@pytest.mark.django_db
class TestDeleteCreditsPageInstances(TestMigrations):

app = "pages"
migrate_from = "0007_create_svgimageblock"
migrate_to = "0008_delete_creditspage_instances"
Expand Down
1 change: 0 additions & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ django-debug-toolbar
pre-commit
black

pytest-ordering
# Using a fork of django-fixture-magic until this PR is merged:
# https://github.com/davedash/django-fixture-magic/pull/76
# (merge_fixtures with natural keys)
Expand Down
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
pytest>=4.6 # required for pytest-cov
pytest-django>=4.1.0,<4.5.0
pytest-cov
pytest-order
wheel
django-dbml>=0.6.0
percy-selenium
Expand Down

0 comments on commit 1ebca33

Please sign in to comment.