forked from SatelliteQE/robottelo
-
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.
This change adds a new fixture_cli.py script under the scripts directory. The basic usage of this script is to take in a space-separated list of global fixtures and run them together in a single temporary test. e.g. python scripts/fixture_cli.py module_ak_with_synced_repo module_lce Additionally, I had to make some minor adjustments to a couple of plugins since this temporary test doesn't follow the same rules as the rest of our framework.
- Loading branch information
1 parent
b86f5b4
commit c7abeac
Showing
3 changed files
with
51 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
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,46 @@ | ||
from pathlib import Path | ||
|
||
import click | ||
import pytest | ||
|
||
|
||
@click.command() | ||
@click.argument("fixtures", nargs=-1, required=True) | ||
@click.option( | ||
"--from-file", | ||
"-f", | ||
type=click.File("w"), | ||
help="Run the fixtures from within a file, inheriting the file's context.", | ||
) | ||
def run_fixtures(fixtures, from_file): | ||
"""Create a temporary test that depends on each fixture, then run it. | ||
You can also run the fixtures from the context of a file, which is useful when testing fixtures | ||
that don't live at a global scope. | ||
Examples: | ||
python scripts/fixture_cli.py module_published_cv module_subscribe_satellite | ||
python scripts/fixture_cli.py module_lce --from-file tests/foreman/api/test_activationkey.py | ||
""" | ||
fixture_string = ", ".join(filter(None, fixtures)) | ||
test_template = f"def test_fake({fixture_string}):\n assert True" | ||
if from_file: | ||
from_file = Path(from_file.name) | ||
# inject the test at the end of the file | ||
with from_file.open("a") as f: | ||
eof_pos = f.tell() | ||
f.write(f"\n\n{test_template}") | ||
pytest.main(["-qq", str(from_file.resolve()), "-k", "test_fake"]) | ||
# remove the test from the file | ||
with from_file.open("r+") as f: | ||
f.seek(eof_pos) | ||
f.truncate() | ||
else: | ||
temp_file = Path("test_DELETEME.py") | ||
temp_file.write_text(test_template) | ||
pytest.main(["-qq", str(temp_file)]) | ||
temp_file.unlink() | ||
|
||
|
||
if __name__ == "__main__": | ||
run_fixtures() |