run_timid.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
  2. # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
  3. # Test that the --timid command line argument properly swaps the tracer
  4. # function for a simpler one.
  5. #
  6. # This is complicated by the fact that the tests are run twice for each
  7. # version: once with a compiled C-based trace function, and once without
  8. # it, to also test the Python trace function. So this test has to examine
  9. # an environment variable set in igor.py to know whether to expect to see
  10. # the C trace function or not.
  11. import os
  12. # When meta-coverage testing, this test doesn't work, because it finds
  13. # coverage.py's own trace function.
  14. if os.environ.get('COVERAGE_COVERAGE', ''):
  15. skip("Can't test timid during coverage measurement.")
  16. copy("src", "out")
  17. run("""
  18. python showtrace.py none
  19. coverage run showtrace.py regular
  20. coverage run --timid showtrace.py timid
  21. """, rundir="out", outfile="showtraceout.txt")
  22. # When running without coverage, no trace function
  23. # When running timidly, the trace function is always Python.
  24. contains("out/showtraceout.txt",
  25. "none None",
  26. "timid PyTracer",
  27. )
  28. if os.environ.get('COVERAGE_TEST_TRACER', 'c') == 'c':
  29. # If the C trace function is being tested, then regular running should have
  30. # the C function, which registers itself as f_trace.
  31. contains("out/showtraceout.txt", "regular CTracer")
  32. else:
  33. # If the Python trace function is being tested, then regular running will
  34. # also show the Python function.
  35. contains("out/showtraceout.txt", "regular PyTracer")
  36. clean("out")