Skip to content

[Bug] Python tests are failing under bazel #999

Open
@pyalex

Description

@pyalex

When trying to run tests under bazel bazel test //api/py:api_test --test_output=streamed
all tests are failing with import error. Example:

_________ ERROR collecting api/py/test/lineage/test_parse_group_by.py __________
ImportError while importing test module '/private/var/tmp/_bazel_omoskalenko/916470916a9b457c8ac69ce8ce573113/execroot/chronon/bazel-out/darwin_arm64-fastbuild/bin/api/py/api_test.runfiles/chronon/api/py/test/lineage/test_parse_group_by.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../../../../../../../external/python_3_8_aarch64-apple-darwin/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
api/py/test/lineage/test_parse_group_by.py:18: in <module>
    from ai.chronon import group_by
api/py/ai/chronon/group_by.py:20: in <module>
    import ai.chronon.api.ttypes as ttypes
E   ModuleNotFoundError: No module named 'ai.chronon.api'

The root cause of it: there are two identical Python modules named ai.chronon created under two Bazel packages with outputs:

  • bazel-out/darwin_arm64-fastbuild/bin/api/py/api_test.runfiles/chronon/api/py/
  • bazel-out/darwin_arm64-fastbuild/bin/api/py/api_test.runfiles/chronon/api/thrift/

They both have structure:

ai/
   chronon/
       __init__.py

Both of them added to sys.path. However, Python can't load both of them. When it discovers the first package under chronon/api/py/ it then looks for ai.chronon.api only there.

Possible solutions:

  1. Rename module ai.chronon.api -> ai.chronon_api to work around the module loading issue.
  2. Move bazel target generating thrift to api/py package.

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