-
Notifications
You must be signed in to change notification settings - Fork 0
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
Discover some way to see which files are being tested in runtime #3
Labels
documentation
Improvements or additions to documentation
Comments
It's possible observe the functions call in runtime by using trace module. See below a brief usage of the trace module in a pytest Tests file: from dependency import method_1
from dependency_2 import method_2
from dependency_3 import method_3
def test_method_1():
assert method_1() == 'I am the method 1'
def test_method_2():
assert method_1() == 'I am the method 1'
assert method_2() == 'I am the method 2'
def test_method_3():
assert False conftest: import sys
import trace
import functools
tracers = []
def pytest_pyfunc_call(pyfuncitem):
test_function = pyfuncitem.obj
# Trace each test individually
tracer = trace.Trace(trace=0, count=1, countfuncs=1, ignoredirs=[sys.prefix, sys.exec_prefix])
tracers.append(tracer)
@functools.wraps(test_function)
def tracer_wrapper(*args, **kwargs):
tracer.runfunc(test_function, *args, **kwargs)
pyfuncitem.obj = tracer_wrapper
def pytest_sessionfinish(session, exitstatus):
for i, tracer in enumerate(tracers):
results = tracer.results()
calls = sorted(results.calledfuncs)[:-1] # ignore the test function call itself
for filename, modulename, funcname in calls:
# ignore Python internal calls
if not filename.startswith(sys.prefix) and not filename.startswith(sys.exec_prefix):
print(f'Test #{i + 1} file dependency:', filename) Output:
|
By the results we can implement Ekstazi as the original. Let's create a Pytest Plugin for Ekstazi algorithm. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See if we can do the same as original Ekstazi do in Java, observing the files that are being used in runtime. If we can't do that, our next approach would be read the test files before running the test suite, and check import files and their usage in the test cases.
The next steps depends on the success of the research, we would create a function to get dependecies of each test case in a test file, or create a wrapper to execute the tests and collect their dependencies.
The text was updated successfully, but these errors were encountered: