lk-geimfari / mimesis

Mimesis is a robust data generator for Python that can produce a wide range of fake data in multiple languages.

Home Page:https://mimesis.name

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Codecov reporting wrong coverage information.

lk-geimfari opened this issue · comments

commented

I have no idea why, but commit 79f6257 (Add pytest entry in pyproject.toml) decreased coverage by 42.21%. Clearly, Codecov is reporting incorrect coverage information and the question is "Why"?

@sobolevn Would you have any guesses about that? Ever run into anything like this?

This is what happens when we comment out the pytest plugin: https://app.codecov.io/gh/lk-geimfari/mimesis/pull/1502

The coverage increased to 99%.

Try to move imports inside the fixture functions. sys.modules is populated too early.

@sobolevn Do you mean like this?

@pytest.fixture(scope="session")
def _mimesis_cache() -> _CacheCallable:
    from mimesis.locales import Locale
    from mimesis.schema import Field

    cached_instances: dict[Locale, Field] = {}

    def factory(locale: Locale) -> Field:
        if locale not in cached_instances:
            cached_instances[locale] = Field(locale)
        return cached_instances[locale]

    return factory


@pytest.fixture()
def mimesis_locale():  # type: ignore
    """Specifies which locale to use."""
    from mimesis.locales import Locale

    return Locale.DEFAULT

Alas, it didn't helped.

This is due to how the import system works and how you're using __init__.py.
Neither are wrong or bad.

When python tries to import mimesis.plugins.pytest, it loads mimesis.__init__.py and looks for plugins.
Because the init refers to most of the files in the package, they're all loaded too early.

You can see this in action by doing the following:
Modify as many files as you dare in the mimesis folder with the following line:
from pathlib import Path; (Path(__file__).parent / Path(__file__).stem).touch()

Now run the python repl and enter this: from mimesis.plugins import bloop

You'll get a few new files created for your trouble:
image

This is due to how the import system works and how you're using __init__.py. Neither are wrong or bad.

When python tries to import mimesis.plugins.pytest, it loads mimesis.__init__.py and looks for plugins. Because the init refers to most of the files in the package, they're all loaded too early.

You can see this in action by doing the following: Modify as many files as you dare in the mimesis folder with the following line: from pathlib import Path; (Path(__file__).parent / Path(__file__).stem).touch()

Now run the python repl and enter this: from mimesis.plugins import bloop

You'll get a few new files created for your trouble: image

Yeah, I get it, but i did not figured out how can I fix this without breaking anything. Ideas or PR are welcomen.