forked from samba-in-kubernetes/sit-test-cases
-
Notifications
You must be signed in to change notification settings - Fork 0
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 fixture
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. Old approach: - All the different tests are called from test_mount.py: https://github.com/samba-in-kubernetes/sit-test-cases/blob/main/testcases/mount/test_mount.py - Test_mount.py creates a mount, the required tests are called and then test_mount.py cleans the mount. New approach : - This PR complies with the proposal to use fixtures in order to remove all the load on one single module: samba-in-kubernetes#25 (comment) samba-in-kubernetes#25 (comment) - The tests are no more called from test_mount.py. - Setting up of mount and tearing down of mount is taken care by setup and teardown fixture which is defined in testcases/mount/conftest.py More information about fixtures: https://docs.pytest.org/en/6.2.x/fixture.html - With this change, test files remain the same, but the initiator function starts with keyword test and the each test module starts with keyword 'test' That way the tests are called by pytest. Usage of setup and teardown fixture becomes easily possible. We no more need to to call the test function explictly. This also helps with easy debugging and better understanding of the code, as the tests will be failed at individual mount/IO test. In this case, pytest clearly points which test among test_mount_io.py, test_mount_dbm.py and test_mount_stress.py are failing. Can be very useful - when more and more tests are added - when we want to parse test results in sit-environment project Fixes: samba-in-kubernetes#30 Signed-off-by: Shwetha K Acharya <Shwetha.K.Acharya@ibm.com>
- Loading branch information
1 parent
7ddd860
commit 70a9c0d
Showing
5 changed files
with
77 additions
and
81 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,55 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import pytest | ||
import os | ||
import shutil | ||
import testhelper | ||
import typing | ||
from pathlib import Path | ||
|
||
test_info_file = os.getenv("TEST_INFO_FILE") | ||
test_info = testhelper.read_yaml(test_info_file) | ||
|
||
|
||
@pytest.fixture | ||
def setup_mount( | ||
first_ipaddr: str, share_name: str | ||
) -> typing.Generator[Path, None, None]: | ||
flag_mounted: bool = False | ||
tmp_root = testhelper.get_tmp_root() | ||
mount_point = testhelper.get_tmp_mount_point(tmp_root) | ||
try: | ||
mount_params = testhelper.get_mount_parameters( | ||
testhelper.read_yaml(test_info_file), share_name | ||
) | ||
mount_params["host"] = first_ipaddr | ||
|
||
# mount cifs share | ||
testhelper.cifs_mount(mount_params, mount_point) | ||
flag_mounted = True | ||
test_dir = mount_point / "mount_test" | ||
test_dir.mkdir() | ||
except Exception as e: | ||
raise Exception(f"Setup failed: {str(e)}") | ||
|
||
# Yield the setup result | ||
yield test_dir | ||
|
||
# Perform teardown after the test has run | ||
try: | ||
if flag_mounted and test_dir: | ||
shutil.rmtree(test_dir, ignore_errors=True) | ||
testhelper.cifs_umount(mount_point) | ||
mount_point.rmdir() | ||
tmp_root.rmdir() | ||
except Exception as e: | ||
raise Exception(f"Teardown failed: {str(e)}") | ||
|
||
|
||
def generate_mount_check() -> typing.List[typing.Tuple[str, str]]: | ||
first_ipaddr = test_info["public_interfaces"][0] | ||
exported_sharenames = test_info.get("exported_sharenames", []) | ||
arr = [] | ||
for share_name in exported_sharenames: | ||
arr.append((first_ipaddr, share_name)) | ||
return arr |
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