2424import logging
2525import os
2626import subprocess
27+ import tempfile
2728
2829import psycopg2
2930import psycopg2 .extensions
3031import pytest
3132
33+ import d1_gmn .app .sciobj_store
34+
35+ import d1_test .instance_generator .random_data
3236import d1_test .sample
3337
3438from d1_client .cnclient_1_2 import CoordinatingNodeClient_1_2 as cn_v1
@@ -102,7 +106,7 @@ def pytest_addoption(parser):
102106 '--skip-clear' , action = 'store_true' , help = 'Clear the list of passed tests'
103107 )
104108 parser .addoption (
105- '--skip-list ' , action = 'store_true' , help = 'Print the list of passed tests'
109+ '--skip-print ' , action = 'store_true' , help = 'Print the list of passed tests'
106110 )
107111
108112
@@ -113,18 +117,20 @@ def pytest_sessionstart(session):
113117 """Called by pytest before calling session.main()"""
114118 if pytest .config .getoption ('--sample-tidy' ):
115119 d1_test .sample .start_tidy ()
120+ pytest .exit ('Tidy started. Run complete to complete' )
116121 if pytest .config .getoption ('--skip-clear' ):
117122 _clear_skip_list ()
118- if pytest .config .getoption ('--skip-list ' ):
123+ if pytest .config .getoption ('--skip-print ' ):
119124 _print_skip_list ()
120125
121126
122127def pytest_sessionfinish (session , exitstatus ):
123128 """Called by pytest after the test session ends"""
124129 # if exitstatus != 2:
125- skipped_count = pytest .config .cache .get (D1_SKIP_COUNT , 0 )
126- if skipped_count :
127- logging .warn ('Skipped {} previously passed tests' .format (skipped_count ))
130+ if pytest .config .getoption ('--skip' ):
131+ skipped_count = pytest .config .cache .get (D1_SKIP_COUNT , 0 )
132+ if skipped_count :
133+ logging .warn ('Skipped {} previously passed tests' .format (skipped_count ))
128134
129135
130136@pytest .hookimpl (tryfirst = True , hookwrapper = True )
@@ -298,20 +304,34 @@ def mn_client_v1_v2(request):
298304 yield request .param (MOCK_BASE_URL )
299305
300306
307+ # Settings
308+
309+
310+ @pytest .fixture (scope = 'session' , autouse = True )
311+ def set_unique_sciobj_store_path (request ):
312+ tmp_store_path = os .path .join (
313+ tempfile .gettempdir (), 'gmn_test_obj_store_{}{}' .format (
314+ d1_test .instance_generator .random_data .random_lower_ascii (
315+ min_len = 12 , max_len = 12
316+ ), get_xdist_suffix (request )
317+ )
318+ )
319+ django .conf .settings .OBJECT_STORE_PATH = tmp_store_path
320+ d1_gmn .app .sciobj_store .create_clean_tmp_store ()
321+
322+
301323# DB fixtures
302324
303325
304326@pytest .yield_fixture (scope = 'session' )
305327def django_db_setup (request , django_db_blocker ):
306328 """Set up DB fixture
307329 """
308- xdist_suffix = getattr (request .config , 'slaveinput' , {}).get ('slaveid' , '' )
309-
310330 logging .info ('Setting up DB fixture' )
311331
312332 test_db_key = 'default'
313333 test_db_name = django .conf .settings .DATABASES [test_db_key ]['NAME' ]
314- test_db_name += xdist_suffix
334+ test_db_name += get_xdist_suffix ( request )
315335 django .conf .settings .DATABASES [test_db_key ]['NAME' ] = test_db_name
316336
317337 template_db_key = 'template'
@@ -339,6 +359,15 @@ def django_db_setup(request, django_db_blocker):
339359 yield
340360
341361
362+ def get_xdist_suffix (request ):
363+ """When running in parallel with xdist, each thread gets a different suffix.
364+ - In parallel run, return '_gw1', etc.
365+ - In single run, return ''.
366+ """
367+ s = getattr (request .config , 'slaveinput' , {}).get ('slaveid' )
368+ return '_{}' .format (s ) if s is not None else ''
369+
370+
342371def create_db_from_template (test_db_name , template_db_name ):
343372 logging .info (
344373 'Creating test DB from template. test_db="{}" template_db="{}"' .
0 commit comments