diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7cd07b1..2a31da2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,7 +40,11 @@ jobs: env: EXECUTING_SLOW_TESTS: 1 run: | - coverage run --include=executing/executing.py --append -m pytest tests + # COVERAGE_PROCESS_START defines the path to the coverage config for coverage-enable-subprocess + export COVERAGE_PROCESS_START=${GITHUB_WORKSPACE}/setup.cfg + coverage run -m pytest tests + # combine the coverage of all subprocesses + coverage combine coverage report -m - name: Coveralls Python uses: AndreMiras/coveralls-python-action@v20201129 diff --git a/setup.cfg b/setup.cfg index d22b4e2..3ee513e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,7 +32,10 @@ install_requires = [options.extras_require] tests= asttokens>=2.1.0 + ipython pytest + coverage + coverage-enable-subprocess littleutils rich; python_version >='3.11' @@ -41,6 +44,9 @@ executing = py.typed [coverage:run] relative_files = True +include = executing/executing.py +parallel = true +branch = true [bdist_wheel] universal=1 diff --git a/tests/test_ipython.py b/tests/test_ipython.py new file mode 100644 index 0000000..dbdd662 --- /dev/null +++ b/tests/test_ipython.py @@ -0,0 +1,41 @@ +import subprocess as sp +import sys +import pytest + + +def run(input): + p = sp.run( + [sys.executable, "-m", "IPython", "--colors=nocolor", "--simple-prompt"], + input=input.encode("utf8"), + stdout=sp.PIPE, + ) + output = p.stdout.decode("utf8") + print(output) + return output + + +test_function_code = """ +from executing import Source +import inspect +import ast + +def test(): + frame = inspect.currentframe() + ex = Source.executing(frame.f_back) + print(ex.node) + if not isinstance(ex.node,ast.Call): + print("test failure") + if not ex.node.func.id=="test": + print("test failure") + +""" + + +def test_one_lookup(): + p = run(test_function_code + "test()") + assert "test failure" not in p + + +def test_two_statement_lookups(): + p = run(test_function_code + "test();test()") + assert "test failure" in p