@pytest.fixture
def temporary_table():
 bigquery_client = bigquery.Client()
 dataset = bigquery_client.dataset(DATASET_ID)
 tables = []
 def factory(table_name):
  new_table = dataset.table(table_name)
  if new_table.exists():
   new_table.delete()
  tables.append(new_table)
  return new_table
 (yield factory)
 for table in tables:
  if table.exists():
   table.delete()

@ pytest . fixture def temporary_table ( ) : bigquery_client = bigquery . Client ( ) dataset = bigquery_client . dataset ( DATASET_ID ) tables = [ ] def factory ( table_name ) : new_table = dataset . table ( table_name ) if new_table . exists ( ) : new_table . delete ( ) tables . append ( new_table ) return new_table ( yield factory ) for table in tables : if table . exists ( ) : table . delete ( )
fixture that returns a factory for tables that do not yet exist and will be automatically deleted after the test .