Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Gold google-analyzer tests #997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

bobhancockg
Copy link
Contributor

This commit fixes an ImportError: attempted relative import beyond top-level package that occurred when running tests in examples/google-ads-account-analyzer-demo/tests/test_analyzer.py using standard test discovery.

The import mechanism for the analyzer module within test_analyzer.py has been made more robust by dynamically adding the parent directory (examples/google-ads-account-analyzer-demo) to sys.path before attempting the import. This ensures that the analyzer module can be correctly located regardless of how the tests are invoked (e.g., direct execution, unittest discover).

The changes ensure that tests can be reliably run from the repository root using commands like python -m unittest discover -s examples/google-ads-account-analyzer-demo/tests -p test_analyzer.py.

Add test suite for Google Ads Account Analyzer Demo and ensure v19 API usage.

This commit introduces a test suite for the `analyzer.py` script located in `examples/google-ads-account-analyzer-demo/`.

Key changes include:
- Created a new `tests` subdirectory within `examples/google-ads-account-analyzer-demo/`.
- Added `test_analyzer.py` containing unit tests for the `account_hierarchy_module` and `get_users_module` functions.
- Implemented comprehensive mocking for the Google Ads API client, services, and API responses to ensure tests are isolated and cover various scenarios:
    - `account_hierarchy_module`: Tested with and without a specific customer ID, simulating different account structures and API responses.
    - `get_users_module`: Tested by mocking API responses for user access information.
- Ensured that the Google Ads API v19 is usable by confirming the current client library version (26.1.0) already includes v19 support, making library updates unnecessary for this specific requirement. The tests are written to be compatible with v19 API structures where applicable.
- Added `__init__.py` to the new test directory.
- All tests pass, verifying the core functionality of the analyzer script and its output formatting.
This commit fixes an `ImportError: attempted relative import beyond top-level package` that occurred when running tests in `examples/google-ads-account-analyzer-demo/tests/test_analyzer.py` using standard test discovery.

The import mechanism for the `analyzer` module within `test_analyzer.py` has been made more robust by dynamically adding the parent directory (`examples/google-ads-account-analyzer-demo`) to `sys.path` before attempting the import. This ensures that the `analyzer` module can be correctly located regardless of how the tests are invoked (e.g., direct execution, `unittest discover`).

The changes ensure that tests can be reliably run from the repository root using commands like `python -m unittest discover -s examples/google-ads-account-analyzer-demo/tests -p test_analyzer.py`.
@bobhancockg bobhancockg requested a review from a team as a code owner June 1, 2025 00:21
@BenRKarl BenRKarl added the kokoro:run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Jun 5, 2025
@kokoro-team kokoro-team removed the kokoro:run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Jun 5, 2025
@BenRKarl BenRKarl added the kokoro:force-run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Jun 5, 2025
@kokoro-team kokoro-team removed the kokoro:force-run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Jun 5, 2025
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.

3 participants