question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Some models are skipped by the builder when running under pytest

See original GitHub issue

If have two questions:

  1. 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)

  2. 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:closed
  • Created 3 years ago
  • Comments:16

github_iconTop GitHub Comments

1reaction
kettenbach-itcommented, Jun 10, 2022

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.

1reaction
markstewardcommented, May 7, 2022

It’s added by configure_mappers, but as I pointed out above that you must call make_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. If make_versioned isn’t hit first, that’s your problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to I display why some tests where skipped while using py ...
When you run py.test, you can pass -rsx to report skipped tests. From py.test --help : -r chars show extra test summary info...
Read more >
pytest.skip inside doctests does not work ... - GitHub
skip works by raising an exception, which is then captured by doctest which then fails the test. At first glance it doesn't seem...
Read more >
Deprecations and Removals — pytest documentation
This page lists all pytest features that are currently deprecated or have been removed in past major releases. The objective is to give...
Read more >
pytest Documentation - Read the Docs
2.13 How to use skip and xfail to deal with tests that cannot succeed . ... pytest will run all files of the...
Read more >
Allure Framework
Executors - information on test executors that were used to run the tests. History Trend - if tests accumulated some historical data, it's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found