From 78a539a2a51e0cb39ee29e23efbd748d7a7c443b Mon Sep 17 00:00:00 2001 From: Ram Rachum Date: Tue, 18 Jun 2019 20:21:51 +0200 Subject: [PATCH] Massaging some code --- README.md | 4 +++- pysnooper/tracer.py | 2 +- tests/test_pysnooper.py | 13 +++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index fae65a3..a1e9907 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,9 @@ Exclude specific keys/attributes/indices with the `exclude` parameter, e.g. `Att Add a slice after `Indices` to only see the values within that slice, e.g. `Indices('z')[-3:]`. -`PYSNOOPER_DISABLED` as an environment variable, can be used to activate or deactivate pysnooner. Pysnooper is deactivated by setting the parameter to a non-empty value, and active by default. +```console +$ export PYSNOOPER_DISABLED=1 # This makes PySnooper not do any snooping +``` # Contribute # diff --git a/pysnooper/tracer.py b/pysnooper/tracer.py index f9b6544..c4a6413 100644 --- a/pysnooper/tracer.py +++ b/pysnooper/tracer.py @@ -140,7 +140,7 @@ class FileWriter(object): thread_global = threading.local() -DISABLED = os.getenv("PYSNOOPER_DISABLED", "") +DISABLED = bool(os.getenv('PYSNOOPER_DISABLED', '')) class Tracer: ''' diff --git a/tests/test_pysnooper.py b/tests/test_pysnooper.py index 52b8a2e..0b93845 100644 --- a/tests/test_pysnooper.py +++ b/tests/test_pysnooper.py @@ -1175,7 +1175,7 @@ def test_custom_repr(): ) -def test_activate_deactivate_snoop(): +def test_disable(): string_io = io.StringIO() def my_function(foo): @@ -1183,11 +1183,8 @@ def test_activate_deactivate_snoop(): y = 8 return x + y - pysnooper.tracer.DISABLED = '1' - with pysnooper.snoop(string_io): - result = my_function('baba') + with mini_toolbox.TempValueSetter((pysnooper.tracer, 'DISABLED'), True): + with pysnooper.snoop(string_io): + result = my_function('baba') output = string_io.getvalue() - assert output == "" - - pysnooper.tracer.DISABLED = '' - test_string_io() + assert not output