Cited:
Prior to using the nose framework, the log was used to generate logs using the--logging-config log file, which is visible before the Python nose test framework is fully described in four.
But after using a period of time, issued a problem, generated reports only error prompts, no logs, view nose's official website, nose default support to display the log, as follows:
The script is as follows:
#Coding:utf-8" "Created on June 22, 2016 @author:huzq" "ImportLogging fromTest_caseImportNew fromNose.toolsImportOk_ fromNose.toolsImporteq_ImportNoseImportOS fromNose.plugins.attribImportattr fromNose.plugins.skipImportskiptestImportSYS#TODO:JFJFJFLog = Logging.getlogger (__name__)deftest_learn_1 (): U" "Test Canceled" " Print 'XXX'Log.info ("AFDFFDFDFD") #Raise Skiptest #print "test_lean_1" #Pass #assert 1==2Eq_ (7, 9, Msg=u"Error") Test_learn_1.slow=1@attr (Mode=2) deftest_lean_2 (): U" "Test Failed" " Try: Print "test_learn_2"Ok_ (4==3,msg="XXX") Printsys._getframe (). F_code.co_nameexceptException:Printsys._getframe (). F_code.co_name @attr (Mode=2) deftest_lean_3 (): U" "Test Success" " Pass defsetUp ():#set_trace () GlobalaPrint "0001 Test SetUp" #addcleanup (AA) defTearDown ():Print "0001 Test teardown"a='Resource Setup'b='C' #assert A==b Printa
As you can see, the logs and print logs in the report are also printed.
Problem analysis
But there's a problem with the log, the format doesn't seem so beautiful
Then we'll revisit the nose logcapture:capture logging during tests
The following parameters are supported:
--nologcapturedisable logging Capture plugin. Logging configuration would be a left intact. [Nose_nologcapture] do not grab log--logging-format=formatspecify custom Format toPrintstatements. Uses the same format as used by standard logging handlers. [Nose_logformat] Custom log format--logging-datefmt=formatspecify Custom Date/time format toPrintstatements. Uses the same format as used by standard logging handlers. [Nose_logdatefmt]log Time Format--logging-filter=Filterspecify which statements to filterinch/out. By default, everything isCaptured. If the output isToo verbose, use the This option to the filter out needless output. Example:filter=foo would capture statements issued only to FooorFoo.what.ever.sub but notFoobarorOther logger. Specify multiple loggers with Comma:filter=foo,bar,baz. If any logger name isPrefixed with a minus, eg Filter=-foo, it'll be excluded rather than included. Default:exclude Logging Messages fromNose itself (-nose). [Nose_logfilter]log Filter--logging-clear-Handlersclear All other logging handlers--logging-level=Defaultset The log level to capture
And then we're going to show you an example of
--nologcapture This doesn't explain, it won't crawl the log.
--logging-format:
The default format is:
' % (name) s:% (levelname) s:% (message) s'
As you can see, the default format is no date, we can redefine the date
Nosetests-v test_case_0001.py L--logging-format=% (asctime) s:% (name) s:% (levelname) s:%-v test_ case_0001.py --logging-format="% (asctime) s:% (name) s:% (levelname) s:% (message) s"
Note that dates with spaces must be double-quoted, single quotes not
The results are as follows
--logging-filter
Filter logs, such as to have more than one file to run, different logs to filter, you can use this parameter
Nosetests-v test_case_0001.py --logging-filter=root
Filter only the root log
Using files to define parameters
In the case of more than one parameter, each run to lose so many parameters, inconvenient, you can use the file form to define
When nose executes, the. Noserc or nose.cfg files in the home directory are used by default, and you can write your own files as follows
[nosetests]verbosity=2logging-format=% (asctime) s% (name) s:% (levelname) s:% (message) s
When executed, use the-C to specify the file
Nosetests-v test_case_0001.py-c Nose.ini
Legacy issues:
When running the test, I wanted to use both--logging-file and--logging-format to simultaneously display the log at runtime and crawl logs to the report at run time.
However,--logging-file is the highest level and ignores other log configurations.
So, want to look at the log or results report with a log can only be two selected.
Python Nose Test Framework Overview Seven--Log related