Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use only pytest #51

Merged
merged 15 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ jobs:
env:
EXECUTING_SLOW_TESTS: 1
run: |
coverage run --include=executing/executing.py -m unittest tests.test_main
coverage run --include=executing/executing.py --append -m pytest tests/test_pytest.py
coverage run --include=executing/executing.py --append -m pytest tests
alexmojaki marked this conversation as resolved.
Show resolved Hide resolved
coverage report -m
- name: Coveralls Python
uses: AndreMiras/coveralls-python-action@v20201129
Expand Down
14 changes: 9 additions & 5 deletions executing/executing.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def wrapper(*args):
if hasattr(dis, "get_instructions"):
# noinspection PyUnresolvedReferences
_get_instructions = dis.get_instructions
from dis import Instruction

else:
class Instruction(namedtuple('Instruction', 'offset argval opname starts_line')):
Expand Down Expand Up @@ -534,17 +535,20 @@ def compile_similar_to(source, matching_code):

sentinel = 'io8urthglkjdghvljusketgIYRFYUVGHFRTBGVHKGF78678957647698'

def is_rewritten_by_pytest(code):
return any(
bc.opname != "LOAD_CONST" and isinstance(bc.argval,str) and bc.argval.startswith("@py")
for bc in get_instructions(code)
)


class SentinelNodeFinder(object):
def __init__(self, frame, stmts, tree, lasti, source):
assert_(stmts)
self.frame = frame
self.tree = tree
self.code = code = frame.f_code
self.is_pytest = any(
'pytest' in name.lower()
for group in [code.co_names, code.co_varnames]
for name in group
)
self.is_pytest = is_rewritten_by_pytest(code)

if self.is_pytest:
self.ignore_linenos = frozenset(assert_linenos(tree))
Expand Down
21 changes: 21 additions & 0 deletions tests/global_tester_calls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from .utils import tester

# tester calls tested with test_tester at global scope

assert tester([1, 2, 3]) == [1, 2, 3]

assert tester.asd is tester
assert tester[1 + 2] is tester
assert tester**4 is tester
assert tester * 3 is tester
assert tester - 2 is tester
assert tester + 1 is tester
assert -tester is +tester is ~tester is tester
assert (tester < 7) is tester
assert (tester >= 78) is tester
assert (tester != 79) is tester
# assert (5 != tester != 6) is tester
assert tester.foo(45, False) == 45

assert (tester or 234) == 234
assert (tester and 1123) is tester
Loading