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

Already on GitHub? Sign in to your account

Control of the assert hook #102

Closed
dag opened this Issue May 1, 2011 · 0 comments

Comments

Projects
None yet
1 participant
Owner

dag commented May 1, 2011

Rather than magically enabling the assert hook on import, provide a context manager in which it is enabled, and default to use it on the CLI, with a switch to optionally disable it.

Custom runners would then have to look something like this to use the hook:

with hooked_assert():
    from my.tests.unit import case
Tests([case]).main()
with hooked_assert():
    Tests(['my.tests.unit:case']).main()
  • Less magic
  • Less convenient but not by much
  • Hook disabled after context - cleaner

Maybe then we could also support an argument to control which imports are transformed, without the requirement to import assert_hook:

with hooked_assert('my.tests'):
    from my.tests.unit import case

Then the CLI would simply hook any modules it loads.

  • Less control per-module, but rarely useful anyway (and still possible)
  • More convenient in the most common case
  • No magic import for pyflakes to complain about or developer to forget to add

@dag dag closed this in 2807052 May 22, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment