2

I'm running hundreds of tests on real phones using pytest and appium. Once in a time I'm getting few appium specific errors which are marking tests as failed but nothing was really checked. This errors are like below:

selenium.common.exceptions.WebDriverException: Message: Could not proxy command to remote server. Original error: Error: socket hang up
selenium.common.exceptions.WebDriverException: Message: Could not proxy command to remote server. Original error: Error: read ECONNRESET
selenium.common.exceptions.WebDriverException: Message: Could not proxy command to remote server. Original error: Error: read ECONNREFUSED

I don't want to mark test as failed in case of one of this errors but to skip this specific test.

Is there any possibility in pytest (hook or fixture) in case of failed testcase to check what was the reason of the fail and if there is one of the error messages from list above to change status of the test from FAIL to SKIP?

Edit after commend from @hoefling: I thought about xfail, but then I will have to add this marker to all of the existing tests and to remember about this in the new ones. Also using xfail I'll catch every occurrence of given exception but I want to catch only the ones which have that specific exception message. And mit's the reason why I was thinking about some hook to execute after test.

Wasiq Bhamla
  • 949
  • 1
  • 7
  • 12
dejvidq
  • 21
  • 1
  • 4
  • 1
    Skipping tests that were executed is not that intuitive. What you can do is use the `xfail` marker: `@pytest.mark.xfail(raises=ErrCls)` where `ErrCls` is the exception class, e.g. `@pytest.mark.xfail(raises=RuntimeError)` will xfail the test if it raises an unhandled `RuntimeError`. – hoefling Jan 11 '19 at 12:50
  • @hoefling I thought about xfail but then I'll need to add this marker to all tests I have and to remember about it in case of writing new ones. I was thinking if there is some possibility to do it in another way. – dejvidq Jan 11 '19 at 12:56
  • There are still several options: you can mark all tests implicitly in hooks, also you can skip or xfail a test on setup if the exception is raised in some autouse fixture used to set up the tests. – hoefling Jan 11 '19 at 13:01
  • I'll check this. Thanks! – dejvidq Jan 11 '19 at 13:06
  • @hoefling Thanks for hint with marking tests as xfail. But I have one more question. Do you know if I can also check exception message? I mean to xfail only tests which have correct exception AND exception message? So WebDriverException with message "Correct message" will be xfailed, but WebDriverException with "Wrong message" won't be xfailed? – dejvidq Jan 14 '19 at 08:26

0 Answers0