@@ -512,6 +512,8 @@ def pytest_collection_modifyitems(session, config, items):
512
512
item .add_marker (version_skip )
513
513
else :
514
514
deselected .append (item )
515
+ elif platform_ok :
516
+ selected .append (item )
515
517
items [:] = selected
516
518
config .hook .pytest_deselected (items = deselected )
517
519
# Add OUR OWN test metadata to Item
@@ -886,6 +888,38 @@ def set_sync_write(self) -> None:
886
888
with connect_server (_vars_ ['server' ]) as srv :
887
889
srv .database .set_write_mode (database = self .db_path , mode = DbWriteMode .SYNC )
888
890
891
+ def existing_db_factory (* , filename : str = 'test.fdb' , charset : Optional [str ]= None ,
892
+ user : Optional [str ]= None , password : Optional [str ]= None ,
893
+ config_name : str = 'pytest' , utf8filename : bool = False ):
894
+ """Factory function that returns :doc:`fixture <pytest:explanation/fixtures>` providing
895
+ the `Database` instance to existing database.
896
+
897
+ Arguments:
898
+ filename: Test database filename. It's also possible to specify database alias using
899
+ '#' as prefix, for example `#employee` means alias `employee`.
900
+ The database with this alias must be defined in `databases.conf`.
901
+ charset: Default charset for connections.
902
+ user: User name used to connect the test database. Default is taken from server configuration.
903
+ password: User password used to connect the test database. Default
904
+ is taken from server configuration.
905
+ config_name: Name for database configuration.
906
+ utf8filename: Use utf8filename DPB flag.
907
+
908
+ .. note::
909
+
910
+ The returned instance must be assigned to module-level variable. Name of this variable
911
+ is important, as it's used to reference the fixture in other fixture-factory functions
912
+ that use the database, and the test function itself.
913
+ """
914
+
915
+ @pytest .fixture
916
+ def existing_database_fixture (request : pytest .FixtureRequest ) -> Database :
917
+ db = Database (_vars_ ['databases' ], filename , user , password , charset , debug = str (request .module ),
918
+ config_name = config_name , utf8filename = utf8filename )
919
+ yield db
920
+
921
+ return existing_database_fixture
922
+
889
923
def db_factory (* , filename : str = 'test.fdb' , init : Optional [str ]= None ,
890
924
from_backup : Optional [str ]= None , copy_of : Optional [str ]= None ,
891
925
page_size : Optional [int ]= None , sql_dialect : Optional [int ]= None ,
@@ -1779,7 +1813,7 @@ def execute(self, *, do_not_connect: bool=False, charset: Optional[str]=None,
1779
1813
else :
1780
1814
result : CompletedProcess = run (params , input = self .script ,
1781
1815
encoding = io_enc , capture_output = True )
1782
- if result .returncode and not bool (self .expected_stderr ) and not combine_output :
1816
+ if ( result .returncode or result . stderr ) and not bool (self .expected_stderr ) and not combine_output :
1783
1817
self ._node .add_report_section ('call' , 'ISQL stdout' , result .stdout )
1784
1818
self ._node .add_report_section ('call' , 'ISQL stderr' , result .stderr )
1785
1819
raise ExecutionError ("Test script execution failed" )
@@ -1893,7 +1927,7 @@ def gstat(self, *, switches: List[str], charset: Optional[str]=None,
1893
1927
if connect_db :
1894
1928
params .append (str (self .db .dsn ))
1895
1929
result : CompletedProcess = run (params , encoding = io_enc , capture_output = True )
1896
- if result .returncode and not bool (self .expected_stderr ):
1930
+ if ( result .returncode or result . stderr ) and not bool (self .expected_stderr ):
1897
1931
self ._node .add_report_section ('call' , 'gstat stdout' , result .stdout )
1898
1932
self ._node .add_report_section ('call' , 'gstat stderr' , result .stderr )
1899
1933
raise ExecutionError ("gstat execution failed" )
@@ -1957,7 +1991,7 @@ def gsec(self, *, switches: Optional[List[str]]=None, charset: Optional[str]=Non
1957
1991
params .extend (['-user' , self .db .user , '-password' , self .db .password ])
1958
1992
result : CompletedProcess = run (params , input = input ,
1959
1993
encoding = io_enc , capture_output = True )
1960
- if result .returncode and not bool (self .expected_stderr ):
1994
+ if ( result .returncode or result . stderr ) and not bool (self .expected_stderr ):
1961
1995
self ._node .add_report_section ('call' , 'gsec stdout' , result .stdout )
1962
1996
self ._node .add_report_section ('call' , 'gsec stderr' , result .stderr )
1963
1997
raise ExecutionError ("gsec execution failed" )
@@ -2021,7 +2055,7 @@ def gbak(self, *, switches: Optional[List[str]]=None, charset: Optional[str]=Non
2021
2055
result : CompletedProcess = run (params , encoding = io_enc , stdout = PIPE , stderr = STDOUT )
2022
2056
else :
2023
2057
result : CompletedProcess = run (params , encoding = io_enc , capture_output = True )
2024
- if result .returncode and not (bool (self .expected_stderr ) or combine_output ):
2058
+ if ( result .returncode or result . stderr ) and not (bool (self .expected_stderr ) or combine_output ):
2025
2059
self ._node .add_report_section ('call' , 'gbak stdout' , result .stdout )
2026
2060
self ._node .add_report_section ('call' , 'gbak stderr' , result .stderr )
2027
2061
raise ExecutionError ("gbak execution failed" )
@@ -2084,7 +2118,7 @@ def nbackup(self, *, switches: List[str], charset: Optional[str]=None,
2084
2118
result : CompletedProcess = run (params , encoding = io_enc , stdout = PIPE , stderr = STDOUT )
2085
2119
else :
2086
2120
result : CompletedProcess = run (params , encoding = io_enc , capture_output = True )
2087
- if result .returncode and not (bool (self .expected_stderr ) or combine_output ):
2121
+ if ( result .returncode or result . stderr ) and not (bool (self .expected_stderr ) or combine_output ):
2088
2122
self ._node .add_report_section ('call' , 'nbackup stdout' , result .stdout )
2089
2123
self ._node .add_report_section ('call' , 'nbackup stderr' , result .stderr )
2090
2124
raise ExecutionError ("nbackup execution failed" )
@@ -2148,7 +2182,7 @@ def gfix(self, *, switches: Optional[List[str]]=None, charset: Optional[str]=Non
2148
2182
result : CompletedProcess = run (params , encoding = io_enc , stdout = PIPE , stderr = STDOUT )
2149
2183
else :
2150
2184
result : CompletedProcess = run (params , encoding = io_enc , capture_output = True )
2151
- if result .returncode and not (bool (self .expected_stderr ) or combine_output ):
2185
+ if ( result .returncode or result . stderr ) and not (bool (self .expected_stderr ) or combine_output ):
2152
2186
self ._node .add_report_section ('call' , 'gfix stdout' , result .stdout )
2153
2187
self ._node .add_report_section ('call' , 'gfix stderr' , result .stderr )
2154
2188
raise ExecutionError ("gfix execution failed" )
@@ -2226,7 +2260,7 @@ def isql(self, *, switches: Optional[List[str]]=None, charset: Optional[str]=Non
2226
2260
else :
2227
2261
result : CompletedProcess = run (params , input = input ,
2228
2262
encoding = io_enc , capture_output = True )
2229
- if result .returncode and not (bool (self .expected_stderr ) or combine_output ):
2263
+ if ( result .returncode or result . stderr ) and not (bool (self .expected_stderr ) or combine_output ):
2230
2264
self ._node .add_report_section ('call' , 'ISQL stdout' , result .stdout )
2231
2265
self ._node .add_report_section ('call' , 'ISQL stderr' , result .stderr )
2232
2266
raise ExecutionError ("ISQL execution failed" )
@@ -2289,7 +2323,7 @@ def svcmgr(self, *, switches: Optional[List[str]]=None, charset: Optional[str]=N
2289
2323
if switches is not None :
2290
2324
params .extend (switches )
2291
2325
result : CompletedProcess = run (params , encoding = io_enc , capture_output = True )
2292
- if result .returncode and not bool (self .expected_stderr ):
2326
+ if ( result .returncode or result . stderr ) and not bool (self .expected_stderr ):
2293
2327
self ._node .add_report_section ('call' , 'fbsvcmgr stdout' , result .stdout )
2294
2328
self ._node .add_report_section ('call' , 'fbsvcmgr stderr' , result .stderr )
2295
2329
raise ExecutionError ("fbsvcmgr execution failed" )
0 commit comments