django-test-migrations icon indicating copy to clipboard operation
django-test-migrations copied to clipboard

fix: clear delayed apps cache of migrations project state

Open skarzi opened this issue 3 years ago • 3 comments

I am still thinking about the test (how to write the simplest and minimal version of it), so this PR is a draft, but feel free to write some suggestions in the comments.

Closes #292

skarzi avatar Jun 09 '22 19:06 skarzi

Codecov Report

Merging #294 (670f45e) into master (35bad71) will not change coverage. The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #294   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        18           
  Lines          328       330    +2     
  Branches        46        46           
=========================================
+ Hits           328       330    +2     
Impacted Files Coverage Δ
django_test_migrations/migrator.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 35bad71...670f45e. Read the comment docs.

codecov[bot] avatar Jun 09 '22 19:06 codecov[bot]

Will https://github.com/wemake-services/django-test-migrations/files/8787829/app-state-bug.zip help?

sobolevn avatar Jun 10 '22 07:06 sobolevn

It's useful, but for some reason test from test_bad.py from this ZIP file is always passing. I just extracted a new migration 0006 for the following model:

class ModelWithItem(models.Model):
    """We use this model for testing migrations."""

    some_item = models.ForeignKey(
        'main_app.SomeItem',
        on_delete=models.PROTECT,
    )

and the following test:

@pytest.mark.django_db()
def test_pytest_plugin0006(migrator):
    """Ensure apps cache is delayed."""
    state = migrator.apply_initial_migration(
        ('main_app', '0006_modelwithitem'),
    )

    SomeItem = state.apps.get_model('main_app', 'SomeItem')
    ModelWithItem = state.apps.get_model('main_app', 'ModelWithItem')
    some_item = SomeItem.objects.create(string_field='test', is_clean=True)

    assert ModelWithItem.objects.create(some_item=some_item)

from the ZIP file.

skarzi avatar Jun 13 '22 12:06 skarzi