-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce setup and teardown fixtures
With this change, multiple test modules triggered from testcases/mount can be run as individual tests complying to pytest standards. Also any number of new tests can be added efficiently on the mount. Fixes: #30 Signed-off-by: Shwetha K Acharya <Shwetha.K.Acharya@ibm.com>
- Loading branch information
1 parent
67419de
commit d4a8ae5
Showing
5 changed files
with
99 additions
and
63 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,47 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import pytest | ||
import os | ||
import shutil | ||
import testhelper | ||
import typing | ||
|
||
flag_mounted: bool = False | ||
tmp_root: str | ||
test_dir: str | ||
|
||
|
||
@pytest.fixture | ||
def setup_mount(ipaddr: str, share_name: str) -> str: | ||
global flag_mounted, tmp_root, test_dir | ||
try: | ||
mount_params = testhelper.get_mount_parameters( | ||
os.getenv("TEST_INFO_FILE"), share_name | ||
) | ||
mount_params["host"] = ipaddr | ||
tmp_root = testhelper.get_tmp_root() | ||
mount_point = testhelper.get_tmp_mount_point(tmp_root) | ||
|
||
# mount cifs share | ||
testhelper.cifs_mount(mount_params, mount_point) | ||
flag_mounted = True | ||
test_dir = mount_point + "/mount_test" | ||
os.mkdir(test_dir) | ||
except Exception as e: | ||
raise Exception(f"Setup failed: {str(e)}") | ||
return test_dir | ||
|
||
|
||
@pytest.fixture | ||
def teardown_mount(mount_point: str) -> typing.Generator[None, str, None]: | ||
yield | ||
|
||
global flag_mounted, tmp_root, test_dir | ||
try: | ||
if flag_mounted: | ||
shutil.rmtree(test_dir, ignore_errors=True) | ||
testhelper.cifs_umount(mount_point) | ||
os.rmdir(mount_point) | ||
os.rmdir(tmp_root) | ||
except Exception as e: | ||
raise Exception(f"Teardown failed: {str(e)}") |
This file was deleted.
Oops, something went wrong.
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