Skip to content

Commit

Permalink
Merge pull request #51 from 15r10nk/use-pytest
Browse files Browse the repository at this point in the history
Use only pytest
  • Loading branch information
alexmojaki authored Oct 5, 2022
2 parents 7e08ab2 + 18748f5 commit 38a81d4
Show file tree
Hide file tree
Showing 173 changed files with 425,314 additions and 455,031 deletions.
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
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

0 comments on commit 38a81d4

Please sign in to comment.