-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TST: Add skip_on_exception decorator (#326)
We have tests that might fail for reasons beyond our control. This decorator catches those exceptions and skips those tests when such an error is raised.
- Loading branch information
Showing
8 changed files
with
123 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Utilities for testing purposes. | ||
""" | ||
|
||
from functools import wraps | ||
|
||
|
||
def skip_on_exception(exp): | ||
""" | ||
Skip a test if a specific Exception is raised. This is because | ||
the Exception is raised for reasons beyond our control (e.g. | ||
flakey 3rd-party API). | ||
Parameters | ||
---------- | ||
exp : The Exception under which to execute try-except. | ||
""" | ||
|
||
from pytest import skip | ||
|
||
def outer_wrapper(f): | ||
|
||
@wraps(f) | ||
def wrapper(*args, **kwargs): | ||
try: | ||
f(*args, **kwargs) | ||
except exp as e: | ||
skip(e) | ||
|
||
return wrapper | ||
|
||
return outer_wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import pytest | ||
import pandas_datareader.data as web | ||
|
||
from pandas_datareader._utils import RemoteDataError | ||
from pandas_datareader._testing import skip_on_exception | ||
|
||
|
||
class TestNasdaqSymbols(object): | ||
|
||
@skip_on_exception(RemoteDataError) | ||
def test_get_symbols(self): | ||
try: | ||
symbols = web.DataReader('symbols', 'nasdaq') | ||
except RemoteDataError as e: | ||
pytest.skip(e) | ||
|
||
symbols = web.DataReader('symbols', 'nasdaq') | ||
assert 'IBM' in symbols.index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.