Skip to content

Import proto functions conditionally in testing.py - #1938

Open
mhucka wants to merge 2 commits into
quantumlib:mainfrom
mhucka:import-protobuf-conditionally
Open

Import proto functions conditionally in testing.py#1938
mhucka wants to merge 2 commits into
quantumlib:mainfrom
mhucka:import-protobuf-conditionally

Conversation

@mhucka

@mhucka mhucka commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

The import of proto funnctions in assert_bloq_example_serializes in testing.py failed in the minimal test environment, where protobufs is not imported. It was not caught because testing_test.py did not have a test case for it.

This wraps the import in testing.py in a conditional, and adds a test to testing_test.py.

The import of proto funnctions in `assert_bloq_example_serializes` in
testing.py failed in the minimal test environment, where protobufs is
not imported. It was not caught because testing_test.py did not have a
test case for it.

This wraps the import in testing.py in a conditional, and adds a test to
testing_test.py.
@mhucka
mhucka marked this pull request as ready for review August 17, 2026 22:12
@mhucka
mhucka requested review from NoureldinYosri, fdmalone, mpharrigan and tanujkhattar and removed request for NoureldinYosri and mpharrigan August 17, 2026 22:12

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates assert_bloq_example_serializes to catch ModuleNotFoundError when importing serialization modules, raising a BloqCheckException.na if protobuf is not installed, and adds corresponding unit tests. The feedback suggests a more robust check in the tests by attempting to import from qualtran.serialization.bloq instead of google.protobuf directly, ensuring the test behaves correctly if protobuf is installed but generated proto files are missing.

Comment thread qualtran/testing_test.py
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant