[Python] Fixing 'Import [module] could not be resolved' in pyright

Discussão em 'Python' iniciado por Stack, Agosto 5, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using pyright for type checking and I'm also using pytest for testing inside Visual Studio Code. The folder structure for my tests is to have a 'test' subfolder in the package root . For example

    |
    MyPackage
    |-- __init__.py
    |-- MyModule.py
    |--test
    |-- __init__.py
    |--MyModule_test.py


    I'm organizing things like this as there will be many packages and I want to keep things organized. Inside pytest I have

    import pytest
    import MyPackage.MyModule
    ...


    Pytest is able to discover the tests and run them OK because it has some special ability to adjust its sys.path (or something). However, pyright will just complain that it cannot import the module, Import 'MyPackage.MyModule' could not be resolvedpyright (reportMissingImports). This makes sense, but is there some way to deal with this, either in pyright or in the Visual Studio Code settings to stop this from complaining?

    Continue reading...

Compartilhe esta Página