-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add logging to bitcoin-util-test.py #9023
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
Conversation
jnewbery
commented
Oct 26, 2016
- Use the python standard logging library
- Run all tests and report all failing test-cases (rather than stop after one test case fails)
- If output is different from expected output, log a contextual diff.
Very nice, I was just struggling with some failing tests and thinking about adding logging. Concept ACK, testing. |
outputData = open(testDir + "/" + outputFn).read() | ||
except: | ||
logging.error("Output file " + outputFn + " can not be opened") | ||
raise Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to use raise Exception
instead of raise
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right - raise
is better. I've updated it.
d7df43b
to
57cae38
Compare
Tested ACK d7df43b202f2bbeba3d94e2bbc9a301141bfa62f |
Concept ACK, but I think this makes the test too noisy in the passing case. Ideally tests are silent if nothing is wrong and noisy if they break. Why not just print a diff when the comparison fails, and leave it at that? (in non-verbose mode) |
After some chat with @laanwj can you make this silently pass tests unless |
Easiest way would be to move PASSED messages to the debug level: diff --git a/src/test/bctest.py b/src/test/bctest.py
index e575b22..0e83284 100644
--- a/src/test/bctest.py
+++ b/src/test/bctest.py
@@ -67,7 +67,7 @@ def bctester(testDir, input_basename, buildenv):
for testObj in input_data:
try:
bctest(testDir, testObj, buildenv.exeext)
- logging.info("PASSED: " + testObj["description"])
+ logging.debug("PASSED: " + testObj["description"])
except:
logging.info("FAILED: " + testObj["description"])
failed_testcases.append(testObj["description"]) However |
This helps, you're setting the log level twice. diff --git a/src/test/bitcoin-util-test.py b/src/test/bitcoin-util-test.py
index 3bae55d..c72dc9f 100755
--- a/src/test/bitcoin-util-test.py
+++ b/src/test/bitcoin-util-test.py
@@ -35,12 +35,12 @@ if __name__ == '__main__':
# Create logging handler
ch = logging.StreamHandler(sys.stdout)
if verbose:
- ch.setLevel(logging.DEBUG)
+ level = logging.DEBUG
else:
- ch.setLevel(logging.ERROR)
+ level = logging.ERROR
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
# Add the handlers to the logger
- logging.basicConfig(level=logging.INFO, handlers=[ch])
+ logging.basicConfig(level=level, handlers=[ch])
bctest.bctester(srcdir + "/test/data", "bitcoin-util-test.json", buildenv) |
@laanwj - I believe the log level needs to be set once for the logger and once for the handler. See https://docs.python.org/3/howto/logging.html#logging-flow for how log levels are set in logging. The intent was certainly that without verbose the behaviour would be:
With verbose, both failure and success is logged along with a summary of results. Here's my output when running with and without verbose for a single test failing: NOT VERBOSE:
VERBOSE:
with automated runs ( Are you seeing something different? |
Ah I'm apparently testing with python, the default interpreter in the The first patch doesn't seem to be necessary. Indeed the log level for non-verbose is set to ERROR so the INFO messages should already not get logged. Without that, I always get verbose behavior: $ PYTHONPATH=./test $HOME/projects/bitcoin/bitcoin/src/test/bitcoin-util-test.py -s $HOME/projects/bitcoin/bitcoin/src
INFO:root:PASSED: Creates a blank transaction
INFO:root:PASSED: Creates a blank transaction (output in json)
INFO:root:PASSED: Creates a blank transaction when nothing is piped into bitcoin-tx
INFO:root:PASSED: Creates a blank transaction when nothing is piped into bitcoin-tx (output in json)
INFO:root:PASSED: Deletes a single input from a transaction
INFO:root:PASSED: Deletes a single input from a transaction (output in json)
INFO:root:PASSED: Attempts to delete an input with a bad index from a transaction. Expected to fail.
INFO:root:PASSED: Deletes a single output from a transaction
INFO:root:PASSED: Deletes a single output from a transaction (output in json)
INFO:root:PASSED: Attempts to delete an output with a bad index from a transaction. Expected to fail.
INFO:root:PASSED: Adds an nlocktime to a transaction
INFO:root:PASSED: Adds an nlocktime to a transaction (output in json)
INFO:root:PASSED: Creates a new transaction with three inputs and two outputs
INFO:root:PASSED: Creates a new transaction with three inputs and two outputs (output in json)
INFO:root:PASSED: Creates a new transaction with a single empty output script
INFO:root:PASSED: Creates a new transaction with a single empty output script (output in json)
INFO:root:PASSED: Creates a new transaction with a single input and a single output, and then signs the transaction
INFO:root:PASSED: Creates a new transaction with a single input and a single output, and then signs the transaction (output in json)
INFO:root:PASSED: Attempts to create a new transaction with one input and an output with malformed hex data. Expected to fail
INFO:root:PASSED: Attempts to create a new transaction with one input and an output with no value and malformed hex data. Expected to fail
INFO:root:PASSED: Creates a new transaction with one input, one address output and one data output
INFO:root:PASSED: Creates a new transaction with one input, one address output and one data output (output in json)
INFO:root:PASSED: Creates a new transaction with one input, one address output and one data (zero value) output
INFO:root:PASSED: Creates a new transaction with one input, one address output and one data (zero value) output (output in json)
INFO:root:PASSED: Creates a new transaction with one input with sequence number and one address output
INFO:root:PASSED: Creates a new transaction with one input with sequence number and one address output (output in json)
INFO:root:PASSED: Adds a new input with sequence number to a transaction
INFO:root:PASSED: Adds a new input with sequence number to a transaction (output in json) With python3 I get the behavior you describe. |
Oh, that makes sense. Are you happy for me to bump bitcoin-util-test.py and bctest.py to python3 as part of this PR? |
Right now, all the scripts that are called by the build system work in python 2 and python 3. It seems it is quite easy to keep Python2 compatibility here (I even suggested a fix). But I don't care deeply. |
465c819
to
6be57b0
Compare
The qa python scripts were changed to use python3 in #7737 , so it seems reasonable to me to also move bitcoin-test-util to python3. |
The python scripts that are not invoked by the build system were changed to be Python 3 only. For example |
@laanwj - I went ahead with changing this to Python3 because your last comment was that you didn't care deeply :) I can edit bitcoin-util-test.py again to make it compatible with Python 2 again, but I don't like your patch. The reason that the -v flag wasn't working with Python 2 is that the stream handler
The outcome is that the I'd personally prefer to specify Python 3 to avoid having to think about Python2/3 compatibility issues like this. However, if you think there's a good reason to maintain Python 2 compatibility, I'll spend some more time to come up with a proper fix. Let me know what you think. Note: travis build has failed due to unrelated intermittent failure in |
I don't care deeply, that doesn't mean no one else does. To be clear: breaking python 2 compatibility will possibly result in long discussions (as it means deprecating Python 2 support for "make check"), which have to be done on a higher level than in this PR only, whereas maintaining it means this can be merged fairly quickly. |
needs rebase. |
6be57b0
to
f2eefd6
Compare
- Use the python standard logging library - Run all tests and report all failing test-cases (rather than stop after one test case fails) - If output is different from expected output, log a contextual diff.
f2eefd6
to
32c0d6e
Compare
New squashed commit does the following:
|
Tested ACK 32c0d6e |
32c0d6e Add logging to bitcoin-util-test.py (jnewbery)
32c0d6e Add logging to bitcoin-util-test.py (jnewbery)
32c0d6e Add logging to bitcoin-util-test.py (jnewbery)
32c0d6e Add logging to bitcoin-util-test.py (jnewbery)
bitcoin-util-test.py backports Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#8829 - bitcoin/bitcoin#8830 - bitcoin/bitcoin#8836 - bitcoin/bitcoin#8881 - bitcoin/bitcoin#9032 - bitcoin/bitcoin#9023 - bitcoin/bitcoin#9069 - bitcoin/bitcoin#9945