-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3720 from aknrdureegaesr/test_helper_improvement
Fix chdir leaking on error out of cd-contextmanager of tests/helper.py.
- Loading branch information
Showing
2 changed files
with
27 additions
and
3 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
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,22 @@ | ||
import os | ||
|
||
from .helper import cd | ||
|
||
|
||
class SomeTestError(Exception): | ||
"""An arbitrary error to be thrown by the test.""" | ||
pass | ||
|
||
|
||
def test_test_helper(): | ||
"""Check that the cd test helper duly resets the directory even in spite of an error.""" | ||
old_dir = os.getcwd() | ||
exception_seen = False | ||
try: | ||
with cd(".."): | ||
raise SomeTestError("Just raising an exception, as failing tests sometimes do.") | ||
except SomeTestError: | ||
now_dir = os.getcwd() | ||
assert old_dir == now_dir | ||
exception_seen = True | ||
assert exception_seen |