Skip to content

Module x was previously imported, but not measured (module-not-measured) #664

Open

Description

@graingert-coef

Summary

when running with pytest-cov I get a ' Module x was previously imported, but not measured (module-not-measured)' but it is actually measured.

see the output here:
https://github.com/graingert-coef/coverage-test/actions/runs/11383996856/job/31670778809#step:4:33

full reproducer here: https://github.com/graingert-coef/coverage-test/

Activity

  1. graingert-coef commented on Oct 17, 2024

    @graingert-coef
    Author

    the problem seems to be related to the fact that you end up with ['coverage_test', 'coverage_test'] in self.source_pkgs_unmatched and coverage only removes on instance of it

    https://github.com/nedbat/coveragepy/blob/fb2b49fb1beb810c6d7ee1cfbbf75a3ff8574fbf/coverage/inorout.py#L199

  2. graingert-coef commented on Oct 17, 2024

    @graingert-coef
    Author

    according to this

    help='Path or package name to measure during execution (multi-allowed). '
    'Use --cov= to not do any source filtering and record everything.',
    I can set --cov= but that also results in a warning:

    https://github.com/graingert-coef/coverage-test/pull/1/files#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711R25
    https://github.com/graingert-coef/coverage-test/actions/runs/11384119440/job/31671155042?pr=1#step:4:33

    in this case you end up with ['', 'coverage_test'] in self.source_pkgs_unmatched

  3. graingert-coef commented on Oct 17, 2024

    @graingert-coef
    Author

    If I set "--cov", this works fine - but then running pipx run tox -- src/coverage_test/tests/test_app.py the --cov consumes the path arg and I get CoverageWarning: Module src/coverage_test/tests/test_app.py was never imported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions