13
13
is_windows = False
14
14
if sys .platform in ["win32" , "win64" , "x64" ]:
15
15
is_windows = True
16
+ sys_argv = sys .argv
16
17
pytest_plugins = ["pytester" ] # Adds the "testdir" fixture
17
18
18
19
@@ -1028,8 +1029,7 @@ def pytest_addoption(parser):
1028
1029
folder, such as when running tests in GitHub Actions.""" ,
1029
1030
)
1030
1031
1031
- sys_argv = sys .argv
1032
- arg_join = " " .join (sys .argv )
1032
+ arg_join = " " .join (sys_argv )
1033
1033
sb_config ._browser_shortcut = None
1034
1034
1035
1035
# SeleniumBase does not support pytest-timeout due to hanging browsers.
@@ -1314,11 +1314,11 @@ def pytest_configure(config):
1314
1314
sb_config ._dash_final_summary = None # Dash status to add to html report
1315
1315
sb_config ._html_report_name = None # The name of the pytest html report
1316
1316
1317
- arg_join = " " .join (sys . argv )
1317
+ arg_join = " " .join (sys_argv )
1318
1318
if (
1319
- "-n" in sys . argv
1319
+ "-n" in sys_argv
1320
1320
or " -n=" in arg_join
1321
- or "-c" in sys . argv
1321
+ or "-c" in sys_argv
1322
1322
or (
1323
1323
sys .version_info [0 ] >= 3
1324
1324
and "addopts" in config .inicfg .keys ()
@@ -1330,7 +1330,7 @@ def pytest_configure(config):
1330
1330
):
1331
1331
sb_config ._multithreaded = True
1332
1332
if (
1333
- "--html" in sys . argv
1333
+ "--html" in sys_argv
1334
1334
or " --html=" in arg_join
1335
1335
or (
1336
1336
sys .version_info [0 ] >= 3
@@ -1398,13 +1398,14 @@ def pytest_configure(config):
1398
1398
if sb_config .dash_title :
1399
1399
constants .Dashboard .TITLE = sb_config .dash_title .replace ("_" , " " )
1400
1400
1401
- from seleniumbase .core import log_helper
1402
- from seleniumbase .core import download_helper
1403
- from seleniumbase .core import proxy_helper
1401
+ if "--co" not in sys_argv and "--collect-only" not in sys_argv :
1402
+ from seleniumbase .core import log_helper
1403
+ from seleniumbase .core import download_helper
1404
+ from seleniumbase .core import proxy_helper
1404
1405
1405
- log_helper .log_folder_setup (sb_config .log_path , sb_config .archive_logs )
1406
- download_helper .reset_downloads_folder ()
1407
- proxy_helper .remove_proxy_zip_if_present ()
1406
+ log_helper .log_folder_setup (sb_config .log_path , sb_config .archive_logs )
1407
+ download_helper .reset_downloads_folder ()
1408
+ proxy_helper .remove_proxy_zip_if_present ()
1408
1409
1409
1410
1410
1411
def pytest_sessionstart (session ):
@@ -1470,6 +1471,8 @@ def _create_dashboard_assets_():
1470
1471
1471
1472
1472
1473
def pytest_itemcollected (item ):
1474
+ if "--co" in sys_argv or "--collect-only" in sys_argv :
1475
+ return
1473
1476
if sb_config .dashboard :
1474
1477
sb_config .item_count += 1
1475
1478
test_id , display_id = _get_test_ids_ (item )
@@ -1480,6 +1483,8 @@ def pytest_itemcollected(item):
1480
1483
1481
1484
1482
1485
def pytest_deselected (items ):
1486
+ if "--co" in sys_argv or "--collect-only" in sys_argv :
1487
+ return
1483
1488
if sb_config .dashboard :
1484
1489
sb_config .item_count -= len (items )
1485
1490
for item in items :
@@ -1493,6 +1498,8 @@ def pytest_collection_finish(session):
1493
1498
Print the dashboard path if at least one test runs.
1494
1499
https://docs.pytest.org/en/stable/reference.html
1495
1500
"""
1501
+ if "--co" in sys_argv or "--collect-only" in sys_argv :
1502
+ return
1496
1503
if sb_config .dashboard and len (session .items ) > 0 :
1497
1504
_create_dashboard_assets_ ()
1498
1505
# Output Dashboard info to the console
@@ -1517,6 +1524,8 @@ def pytest_collection_finish(session):
1517
1524
1518
1525
def pytest_runtest_setup (item ):
1519
1526
"""This runs before every test with pytest."""
1527
+ if "--co" in sys_argv or "--collect-only" in sys_argv :
1528
+ return
1520
1529
if sb_config .dashboard :
1521
1530
sb_config ._sbase_detected = False
1522
1531
test_id , display_id = _get_test_ids_ (item )
@@ -1528,6 +1537,8 @@ def pytest_runtest_teardown(item):
1528
1537
"""This runs after every test with pytest.
1529
1538
Make sure that webdriver and headless displays have exited.
1530
1539
(Has zero effect on tests using --reuse-session / --rs)"""
1540
+ if "--co" in sys_argv or "--collect-only" in sys_argv :
1541
+ return
1531
1542
try :
1532
1543
if hasattr (item , "_testcase" ) or hasattr (sb_config , "_sb_pdb_driver" ):
1533
1544
if hasattr (item , "_testcase" ):
@@ -1536,7 +1547,7 @@ def pytest_runtest_teardown(item):
1536
1547
if (
1537
1548
hasattr (self , "driver" )
1538
1549
and self .driver
1539
- and "--pdb" not in sys . argv
1550
+ and "--pdb" not in sys_argv
1540
1551
):
1541
1552
if not is_windows or self .driver .service .process :
1542
1553
self .driver .quit ()
@@ -1557,11 +1568,11 @@ def pytest_runtest_teardown(item):
1557
1568
pass
1558
1569
try :
1559
1570
if hasattr (self , "xvfb" ) and self .xvfb :
1560
- if self .headless_active and "--pdb" not in sys . argv :
1571
+ if self .headless_active and "--pdb" not in sys_argv :
1561
1572
if hasattr (self , "display" ) and self .display :
1562
1573
self .display .stop ()
1563
1574
elif hasattr (self , "headless" ) and self .headless :
1564
- if self .headless_active and "--pdb" not in sys . argv :
1575
+ if self .headless_active and "--pdb" not in sys_argv :
1565
1576
if hasattr (self , "display" ) and self .display :
1566
1577
self .display .stop ()
1567
1578
except Exception :
@@ -1577,6 +1588,8 @@ def pytest_sessionfinish(session):
1577
1588
1578
1589
1579
1590
def pytest_terminal_summary (terminalreporter ):
1591
+ if "--co" in sys_argv or "--collect-only" in sys_argv :
1592
+ return
1580
1593
latest_logs_dir = os .getcwd () + "/latest_logs/"
1581
1594
if sb_config ._multithreaded :
1582
1595
if os .path .exists (latest_logs_dir ) and os .listdir (latest_logs_dir ):
@@ -1657,7 +1670,7 @@ def _perform_pytest_unconfigure_():
1657
1670
the_html_d = None
1658
1671
with open (dashboard_path , "r" , encoding = "utf-8" ) as f :
1659
1672
the_html_d = f .read ()
1660
- if sb_config ._multithreaded and "-c" in sys . argv :
1673
+ if sb_config ._multithreaded and "-c" in sys_argv :
1661
1674
# Threads have "-c" in sys.argv, except for the last
1662
1675
raise Exception ('Break out of "try" block.' )
1663
1676
if sb_config ._multithreaded :
@@ -1748,6 +1761,8 @@ def _perform_pytest_unconfigure_():
1748
1761
1749
1762
def pytest_unconfigure (config ):
1750
1763
"""This runs after all tests have completed with pytest."""
1764
+ if "--co" in sys_argv or "--collect-only" in sys_argv :
1765
+ return
1751
1766
if hasattr (sb_config , "_multithreaded" ) and sb_config ._multithreaded :
1752
1767
import fasteners
1753
1768
@@ -1830,6 +1845,8 @@ def base_method(self):
1830
1845
1831
1846
@pytest .mark .hookwrapper
1832
1847
def pytest_runtest_makereport (item , call ):
1848
+ if "--co" in sys_argv or "--collect-only" in sys_argv :
1849
+ return
1833
1850
pytest_html = item .config .pluginmanager .getplugin ("html" )
1834
1851
outcome = yield
1835
1852
report = outcome .get_result ()
0 commit comments