Skip to content

Commit

Permalink
Update on "Massively refactor the test suite"
Browse files Browse the repository at this point in the history
[ghstack-poisoned]
  • Loading branch information
ezyang committed Dec 20, 2023
1 parent 5352028 commit d280596
Show file tree
Hide file tree
Showing 55 changed files with 3,088 additions and 2,982 deletions.
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ max-line-length = 120
# P208 is a duplicate of C403.
# W503 talks about operator formatting which is too opinionated.
# C901 I like long functions
ignore = E127, E128, E203, E265, E266, E402, E501, E722, P207, P208, W503, C901
# F403 should turn this on for ghstack/, lookup exclude format TODO
ignore = E127, E128, E203, E265, E266, E402, E501, E722, P207, P208, W503, C901, F403, F405
exclude =
.git,
.hg,
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ build
.python-version
.venv/
.vscode
tags
*.log
plan.txt
8 changes: 4 additions & 4 deletions .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ merge_base_with = "origin/master"

[[linter]]
code = 'FLAKE8'
include_patterns = ['**/*.py']
include_patterns = ['**/*.py', '**/*.py.test']
command = [
'python3',
'tools/linter/adapters/flake8_linter.py',
Expand All @@ -13,8 +13,8 @@ command = [

[[linter]]
code = 'MYPY'
include_patterns = ['**/*.py']
exclude_patterns = ['tools/**']
include_patterns = ['**/*.py', '**/*.py.test']
exclude_patterns = ['tools/**', 'conftest.py']
command = [
'python3',
'tools/linter/adapters/mypy_linter.py',
Expand All @@ -25,7 +25,7 @@ command = [

[[linter]]
code = 'UFMT'
include_patterns = ['**/*.py', '**/*.pyi']
include_patterns = ['**/*.py', '**/*.pyi', '**/*.py.test']
command = [
'python3',
'tools/linter/adapters/ufmt_linter.py',
Expand Down
44 changes: 44 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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):
if es := expecttest.EDIT_HISTORY.state.get(self.fspath):
es.clear()
expecttest.EDIT_HISTORY.seen.clear()
runpy.run_path(self.fspath)

def repr_failure(self, excinfo):
excinfo.traceback = excinfo.traceback.cut(path=self.fspath)
return super().repr_failure(excinfo)
Loading

0 comments on commit d280596

Please sign in to comment.