GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: cleanup resources at startup time in system and sample tests · Issue #590 · googleapis/python-bigquery

This repository was archived by the owner on Mar 6, 2026. It is now read-only.
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

test: cleanup resources at startup time in system and sample tests #590

Copy link
Copy link
Closed
#1741
Closed
test: cleanup resources at startup time in system and sample tests#590
#1741
Copy link
Assignees
kiraksi
Labels
api: bigqueryIssues related to the googleapis/python-bigquery API.priority: p3Desirable enhancement or fix. May not be included in next release.samplesIssues that are directly related to samples.type: processA process-related concern. May include testing, release, or the like.

Description

@tswast
tswast
opened on Apr 6, 2021
Issue body actions
  1. Update fixtures to use a consistent prefix, so we can tell which resources are created by python-bigquery (and possibly disambiguate between samples and system tests). Also include a timestamp in the prefix.
  2. List all resources in the project, filter by our prefix, delete those resources that were created >= 24 hours ago.

This will prevent resource leaks from getting too bad. Teardown doesn't always get a chance to run because of intermittent Kokoro errors and timeouts.

Activity

  1. product-auto-label
    added
    api: bigqueryIssues related to the googleapis/python-bigquery API.
    samplesIssues that are directly related to samples.
    on Apr 6, 2021
  2. tswast
    added
    type: processA process-related concern. May include testing, release, or the like.
    on Apr 6, 2021
  3. tswast commented on Apr 6, 2021

    @tswast
    tswast
    on Apr 6, 2021
    ContributorAuthor
    More actions

    I experiment with this in #591 (but we'll still need to cleanup the other tests in the samples/snippets directory, even after that is merged.

    Datasets are the primary resource that we're concerned about, as they contain tables, models, routines. We should be able to cleanup those before the tests run with a fixture like the following:

    RESOURCE_PREFIX = "python_bigquery_samples_snippets"
    
    
    def resource_prefix() -> str:
        timestamp = datetime.datetime.utcnow().strftime("%Y%m%d_%H%M%S")
        random_string = hex(random.randrange(1000000))[2:]
        return f"{RESOURCE_PREFIX}_{timestamp}_{random_string}"
    
    
    @pytest.fixture(scope="session", autouse=True)
    def cleanup_datasets(bigquery_client: bigquery.Client):
        yesterday = datetime.datetime.utcnow() - datetime.timedelta(days=1)
        for dataset in bigquery_client.list_datasets():
            if (
                dataset.dataset_id.startswith(RESOURCE_PREFIX)
                and dataset.created < yesterday
            ):
                bigquery_client.delete_dataset(
                    dataset, delete_contents=True, not_found_ok=True
  4. tswast commented on Apr 6, 2021

    @tswast
    tswast
    on Apr 6, 2021
    ContributorAuthor
    More actions

    Also, we could standardize on the prefix format and put the logic here: https://github.com/googleapis/python-test-utils

  5. chalmerlowe
    added
    priority: p3Desirable enhancement or fix. May not be included in next release.
    on Nov 11, 2022
  6. kiraksi
    self-assigned this
    on Nov 14, 2023
  7. chalmerlowe
    closed this as completedin #1741on Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @kiraksi
    kiraksi

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.priority: p3Desirable enhancement or fix. May not be included in next release.samplesIssues that are directly related to samples.type: processA process-related concern. May include testing, release, or the like.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.