-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Massively refactor the test suite (#229)
Signed-off-by: Edward Z. Yang <[email protected]>
- Loading branch information
Showing
55 changed files
with
3,279 additions
and
3,161 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 |
---|---|---|
|
@@ -8,3 +8,6 @@ build | |
.python-version | ||
.venv/ | ||
.vscode | ||
tags | ||
*.log | ||
plan.txt |
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,42 @@ | ||
# mypy: ignore-errors | ||
|
||
import pathlib | ||
import runpy | ||
|
||
import expecttest | ||
|
||
import ghstack.test_prelude | ||
|
||
import pytest | ||
|
||
|
||
# Adapted from https://stackoverflow.com/questions/56807698/how-to-run-script-as-pytest-test | ||
|
||
|
||
def pytest_collect_file(file_path: pathlib.Path, parent): | ||
# NB: script name must not end with py, due to doctest picking it | ||
# up in that case | ||
if file_path.suffixes == [".py", ".test"]: | ||
return Script.from_parent(parent, path=file_path) | ||
|
||
|
||
class Script(pytest.File): | ||
def collect(self): | ||
yield ScriptItem.from_parent(self, name="default", direct=False) | ||
if self.path.parent.name in ["submit", "unlink"]: | ||
yield ScriptItem.from_parent(self, name="direct", direct=True) | ||
|
||
|
||
class ScriptItem(pytest.Item): | ||
def __init__(self, *, direct, **kwargs): | ||
super().__init__(**kwargs) | ||
self.direct = direct | ||
|
||
def runtest(self): | ||
with ghstack.test_prelude.scoped_test(direct=self.direct): | ||
expecttest.EDIT_HISTORY.reload_file(self.fspath) | ||
runpy.run_path(self.fspath) | ||
|
||
def repr_failure(self, excinfo): | ||
excinfo.traceback = excinfo.traceback.cut(path=self.fspath) | ||
return super().repr_failure(excinfo) |
Oops, something went wrong.