Some models are skipped by the builder when running under pytest
See original GitHub issueIf have two questions:
-
Can the model “User” (given with user_cls=“User”) itself be versioned? In my case the builder skips it (as well as 1:1 model of User called Usersettings)
-
Running under pytest, for my 82 models, 35 (incl. User and UserSettings) don’t get versioned. Why???
Here’s some debugging output generated by a piece of code running on Flask-startup checking for models having no “versioning_manager” attached, counting them as well as all other models and printing the bad ones:
- Running without pytest - just normal Flask:
Real: 82
Bad: 2
All (incl. _versions): 164
Bad models:
<class 'models.usersettings.Usersettings'> has no __versioning_manager__
<class 'models.user.User'> has no __versioning_manager__
=> User and Usersettings which is 1:1 with User don’t get a version_manager
- Running under pytest:
Launching pytest with arguments --capture=sys --no-cov tests
============================= test session starts ==============================
platform darwin -- Python 3.7.7, pytest-5.4.2, py-1.8.0, pluggy-0.13.0 -- /Users/volker/PycharmProjects/verivinum-core-api/venv/bin/python
cachedir: .pytest_cache
plugins: cov-2.8.1, flask-1.0.0, flask-sqlalchemy-1.0.2, forked-1.1.3, mock-1.11.1, pycharm-0.6.0, xdist-1.30.0
collecting ... collected 302 items
[....]
Real: 82
Bad: 35
All (incl. _versions): 131
Bad models:
<class 'models.country.Country'> has no __versioning_manager__
<class 'models.company.Company'> has no __versioning_manager__
<class 'models.ap.Ap'> has no __versioning_manager__
<class 'models.brandtype.Brandtype'> has no __versioning_manager__
<class 'models.brand.Brand'> has no __versioning_manager__
<class 'models.marketsegment.Marketsegment'> has no __versioning_manager__
<class 'models.retaillabel.Retaillabel'> has no __versioning_manager__
<class 'models.store.Store'> has no __versioning_manager__
<class 'models.producttype.Producttype'> has no __versioning_manager__
<class 'models.productsubtype.Productsubtype'> has no __versioning_manager__
<class 'models.productcolor.Productcolor'> has no __versioning_manager__
<class 'models.indicationtype.Indicationtype'> has no __versioning_manager__
<class 'models.indication.Indication'> has no __versioning_manager__
<class 'models.predicate.Predicate'> has no __versioning_manager__
<class 'models.packagingtype.Packagingtype'> has no __versioning_manager__
<class 'models.volume.Volume'> has no __versioning_manager__
<class 'models.siteregion.Siteregion'> has no __versioning_manager__
<class 'models.sitemunicipality.Sitemunicipality'> has no __versioning_manager__
<class 'models.sitemacro.Sitemacro'> has no __versioning_manager__
<class 'models.sitemicro.Sitemicro'> has no __versioning_manager__
<class 'models.sweetnes.Sweetnes'> has no __versioning_manager__
<class 'models.updatecycle.Updatecycle'> has no __versioning_manager__
<class 'models.product.Product'> has no __versioning_manager__
<class 'models.datasource.Datasource'> has no __versioning_manager__
<class 'models.storageroom.Storageroom'> has no __versioning_manager__
<class 'models.storageshelf.Storageshelf'> has no __versioning_manager__
<class 'models.storageboard.Storageboard'> has no __versioning_manager__
<class 'models.currency.Currency'> has no __versioning_manager__
<class 'models.bottletype.Bottletype'> has no __versioning_manager__
<class 'models.bottlecolor.Bottlecolor'> has no __versioning_manager__
<class 'models.closuretype.Closuretype'> has no __versioning_manager__
<class 'models.closuresubtype.Closuresubtype'> has no __versioning_manager__
<class 'models.sample.Sample'> has no __versioning_manager__
<class 'models.usersettings.Usersettings'> has no __versioning_manager__
<class 'models.user.User'> has no __versioning_manager__
Without User and UserSettings, which may simply not be versionable, 33 models remain, for which no version-manager is created under pytest.
For the 33 “bad” models, versioning does not work at all. If pytest does a post, put or delete, the corresponding is not filled.
I tried to debug with PyCharm but I got lost in the depths of the continuum. Things running under pytest are especially hard to debug.
Issue Analytics
- State:
- Created 3 years ago
- Comments:16
Top GitHub Comments
We fixed that in pytest, too. We had to move some imports from the top-level to the method-level to prevent models from being loaded too early.
It’s added by
configure_mappers
, but as I pointed out above that you must callmake_versioned
before defining the models. Everything you’ve said so far still suggests you’re not doing that, and the differences are due to importing models effectively at random.Maybe put in a breakpoint at the definition of your User model and at
make_versioned
. Ifmake_versioned
isn’t hit first, that’s your problem.