Skip to content

test: Add DBAPI 2.0 compliance test suite#16158

Open
bhatt4982 wants to merge 1 commit intodbapi-driver-1from
dbapi-driver-2
Open

test: Add DBAPI 2.0 compliance test suite#16158
bhatt4982 wants to merge 1 commit intodbapi-driver-1from
dbapi-driver-2

Conversation

@bhatt4982
Copy link
Contributor

test: Add DBAPI 2.0 compliance test suite including a base test class, SQL factory, helper utilities, and nox integration.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #16120 🦕

…, SQL factory, helper utilities, and nox integration.
@bhatt4982 bhatt4982 requested review from a team as code owners March 24, 2026 11:18
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the testing infrastructure by introducing a robust DBAPI 2.0 compliance test suite. The new tests are designed to verify that the google-cloud-spanner-dbapi-driver adheres to the Python Database API Specification v2.0, ensuring standardized and predictable behavior. This addition improves the reliability and maintainability of the driver by systematically validating its core functionalities against industry standards.

Highlights

  • New Compliance Test Suite: A new DBAPI 2.0 compliance test suite has been added, including a base test class, SQL factory, and helper utilities.
  • Nox Integration: A dedicated compliance Nox session was introduced to easily run the new DBAPI 2.0 compliance tests.
  • SQL Factory for Dialects: An abstract SQL factory was implemented to generate SQL statements, with a concrete implementation for GoogleSQL, facilitating dialect-specific testing.
  • Comprehensive DBAPI 2.0 Checks: The base test class includes extensive checks for module attributes, connection object methods, cursor object functionalities, and type object constructors as per PEP 249.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 introduces a DBAPI 2.0 compliance test suite, which is a great addition for ensuring driver compatibility. The changes include a new nox session for running these tests, a base test class, a SQL factory for generating test data, and helper utilities. My review focuses on improving the robustness and correctness of the new test infrastructure. I've identified a critical issue in the nox configuration that would prevent the tests from running correctly, and a couple of medium-severity issues related to code robustness and error handling in the test helpers and base class.

MODE,
f"--junitxml=compliance_{session.python}_sponge_log.xml",
*test_paths,
env={},
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The test process requires the SPANNER_EMULATOR_HOST and TEST_DIALECT environment variables, but they are not being passed to session.run. An empty env dictionary is provided, which means the test environment will not have these crucial variables set, causing the tests to fail. You should pass these variables from the nox environment to the test execution environment.

        env={
            "SPANNER_EMULATOR_HOST": os.environ["SPANNER_EMULATOR_HOST"],
            "TEST_DIALECT": os.environ.get("TEST_DIALECT", "GoogleSQL"),
        },



def setup_test_env() -> None:
print(f"Set SPANNER_EMULATOR_HOST to {os.environ['SPANNER_EMULATOR_HOST']}")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using os.environ['SPANNER_EMULATOR_HOST'] can raise a KeyError if the environment variable is not set. Although the nox session checks for this, running tests manually without nox could lead to a crash. It's safer to use the module-level SPANNER_EMULATOR_HOST variable, which is already populated using os.environ.get() and is available in the scope of this function.

Suggested change
print(f"Set SPANNER_EMULATOR_HOST to {os.environ['SPANNER_EMULATOR_HOST']}")
print(f"Set SPANNER_EMULATOR_HOST to {SPANNER_EMULATOR_HOST}")

Comment on lines +82 to +83
except Exception:
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The broad except Exception: pass in the cleanup method silently swallows all exceptions, which can hide important issues during test teardown. This makes debugging failures much harder. It's better to catch more specific exceptions or at least log the error that occurred.

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