-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(approval): add custom Namer class
add custom Namer class to make paramatrized tests work
- Loading branch information
1 parent
1259ed3
commit 56723c2
Showing
4 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
tests/fixtures/approved/test_approval-test_smt_approver-esri-world-imagery.approved.txt
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
tests/fixtures/approved/test_approval-test_smt_approver-osm.approved.txt
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
|
||
from approvaltests import Namer | ||
|
||
from tests import FIXTURE_DIR | ||
|
||
APPROVED_DIR = FIXTURE_DIR / "approved" | ||
|
||
|
||
class PytestNamer(Namer): | ||
def __init__(self): | ||
"""An approval tests Namer for naming approved and received text files. | ||
The Namer includes fixture dir, module, class and function in name. | ||
This class utilizes the `PYTEST_CURRENT_TEST` environment variable, which | ||
consist of the nodeid and the current stage: | ||
`relative/path/to/test_file.py::TestClass::test_func[a] (call)` | ||
For better readability this class formats the filename to something like: | ||
`test_file-TestClass-test_func-a | ||
""" | ||
# TODO: name clashes are possible. | ||
# Include dir names (except tests/integration/) to avoid name clashes | ||
nodeid = os.environ["PYTEST_CURRENT_TEST"] | ||
nodeid_without_dir = nodeid.split("/")[-1] | ||
parts = nodeid_without_dir.split("::") | ||
raw = "-".join(parts) | ||
self.name = ( | ||
raw.replace(".py", "") | ||
.replace("[", "-") | ||
.replace("]", "") | ||
.replace(" (call)", "") | ||
) | ||
|
||
def get_received_filename(self) -> str: | ||
return str(APPROVED_DIR / str(self.name + ".received" + ".txt")) | ||
|
||
def get_approved_filename(self) -> str: | ||
return str(APPROVED_DIR / str(self.name + ".approved" + ".txt")) |