Why does pytest not execute the entire loop #12926
Replies: 2 comments 2 replies
-
pytest with xdist doesn't print anything out when using Probably this issue is in where you catch all exceptions and suppress them https://github.com/tejendrapsingh/for-help/blob/main/using-pytest-for-parallelization.py#L900 Instead you should only catch the exceptions that you expect If you want to catch multiple exceptions and continue a for loop you should use an exception group: exceptions = []
for x in y:
try:
...
except Exception as e:
e.add_note("failed processing {x}")
exceptions.append(e)
if exceptions:
raise ExceptionGroup("multiple errors processing", exceptions) These bare except statements are also bad, and incompatible with a signal handler and BaseException timeout approach: https://github.com/tejendrapsingh/for-help/blob/main/using-pytest-for-parallelization.py#L92 |
Beta Was this translation helpful? Give feedback.
-
I'd suggest you don't use pytest for this at all, as you don't actually seem to be testing anything. If you use Selenium directly from Python, and then use something like the I also agree that your approach to exception handling likely hides bugs in your code - see e.g. The Most Diabolical Python Antipattern – Real Python. |
Beta Was this translation helpful? Give feedback.
-
Hey! I am using the pytest together with seleniumbase for scraping a website. The function that I am passing to pytest has a long loop. pytest however stops before executing the entire loop. I have tried tweaking a few parameters but to no avail. I am posting a picture with a run that did not execute the entire loop. I am also posting the code below.
Beta Was this translation helpful? Give feedback.
All reactions