$2vt~dZddlZddlZddlZddlZddlmcmZddl m Z ddl m Z ddl m Z ddl m Z ddl mZddl mZdd l mZdd l mZddlZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%e#dZ&de'de(fdZ)d8dZ*iZ+dddgie+d<dgdie+d <e+d,e+d!<e*e+d!e+d e+de+d"<Gd#d$Z-d%ed&e(ddfd'Z.ej/d%ede e(e'gdffd(Z0ej/d%ede e(e'gdffd)Z1d*e(d+e(ddfd,Z2ej/d-.d%ede e(e'gdffd/Z3d0eddfd1Z4d2eddfd3Z5d2eddfd4Z6d5e(de e(fd6Z7Gd7dZ8dS)9aReport test results in JUnit-XML format, for use with Jenkins and build integration servers. Based on initial code from Ross Lawley. Output conforms to https://github.com/jenkinsci/xunit-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd N)datetime)Callable)Dict)List)Match)Optional)Tuple)Union)nodes)timing) ExceptionRepr)ReprFileLocation)Config) filename_arg)Parser)FixtureRequest) TestReport)StashKey)TerminalReporterLogXMLargreturncdttdtfd}d}tj||t|S)a!Visually escape invalid XML characters. For example, transforms 'hello\aworld\b' into 'hello#x07world#x08' Note that the #xABs are *not* XML escapes - missing the ampersand «. The idea is to escape visually for the user rather than for XML itself. matchobjrcdt|}|dkrd|zSd|zS)Nz#x%02Xz#x%04X)ordgroup)ris /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/_pytest/junitxml.pyreplzbin_xml_escape..repl3s6   ! ! 99a< a< u [^ -~€-퟿-�က0-ჿFF])rstrresub)rr!illegal_xml_res r bin_xml_escaper'(sO uSz c     W 6.$C 1 11r"ci}|D]X\}}|D]>\}}t|tstt |||z||<?Y||dSN)items isinstancelist TypeErrortypeupdate)leftrightresultklvlkrvrs r merge_familyr7Cs F**,,!!Bkkmm ! !FBb$'' *R)))bF2JJ ! KKr"testcase classnamename_base)filelineurl _base_legacyxunit1xunit2c eZdZdeeefddddfdZdejddfdZ d ed e ddfd Z d ed e ddfd Z de ejfd ZdeddfdZdejfdZd#dedede eddfdZdeddfdZdededefdZdedededdfdZdeddfdZdeddfdZdeddfdZdeddfdZdeddfd Zdeddfd!Zd$d"ZdS)% _NodeReporternodeidxmlrrNc||_||_|jj|_|jj|_d|_g|_g|_i|_dS)N)idrE add_statsfamilyduration propertiesr attrs)selfrDrEs r __init__z_NodeReporter.__init__ZsG+ho  13') %' r"nodecx|j|j|j|dSr))rErItagr append)rNrPs r rSz_NodeReporter.appendds6 48$$$ $r"r:valuecr|jt|t|fdSr))rLrSr#r'rNr:rTs r add_propertyz_NodeReporter.add_propertyhs1 D >%+@+@ABBBBBr"cNt||jt|<dSr))r'rMr#rVs r add_attributez_NodeReporter.add_attributeks" .u 5 5 3t99r"c|jrMtjd}|jD]/\}}|tjd||0|SdSz9Return a Junit node containing custom properties, if any.rLpropertyr:rTN)rLETElementrSrNrLr:rTs r make_properties_nodez"_NodeReporter.make_properties_nodense ? L11J# R R e!!"*Zd%"P"P"PQQQQ tr" testreportct|j}|j}|dd}|jjr |d|jjd|t|d|jdd}|jdt|jd|d<t|dr |j |d<||_|j ||j dkrdSi}|jD],}|t|j d vr|j|||<-||_dS) Nr.)r9r:r<r=r>r@r8)mangle_test_addressrDrMrEprefixinsertjoinr'locationr#hasattrr>r/rJkeysfamilies)rNrbnamesexisting_attrs classnamesrM temp_attrskeys r record_testreportz_NodeReporter.record_testreportwsL#J$5663B3Z 8? 2   a 1 1 1*--"59--'*! !   q ! - 3A 677E&M :u % % *%>E%L  .))) ;( " " F :??$$ 2 2Cht{+J777"&*S/ 3 r"ctjd|jd|jz}|}|||||j|S)Nr8%.3f)time)r^r_rMrKrarSextendr )rNr8rLs r to_xmlz_NodeReporter.to_xmlsc:j$*6DM;QRRR..00  ! OOJ ' ' ' ###r"rRmessagedatactj||}t||_||dS)N)rzr^r_r'textrS)rNrRrzr{rPs r _add_simplez_NodeReporter._add_simples=z#w///"4((  Dr"reportc|jjs |jrdS|j}|j}|j}|jjdkrdSd}|jjdvr||d}|jjdvr2|||dz }|||dd}|jjdvr2|||d z }|||d d}|r|||ddSdS) Nno)logallz Captured Log ) system-outout-errrz Captured Out r) system-errrrz Captured Err r) rElog_passing_testspassed capstdoutcaplog capstderrlogging_prepare_content_write_content)rNr content_out content_log content_err content_alls r write_captured_outputz#_NodeReporter.write_captured_outputs9x) fm  F& m & 8 t # # F 8 ~ - -// =MNNK 8 ? ? ? 400>NOO OK    \ B B BK 8 ? ? ? 400>NOO OK    \ B B BK  C    \ B B B B B C Cr"contentheadercZd|dd|dgS)N P-r)rjcenter)rNrrs r rz_NodeReporter._prepare_contents)yy&--C00'2>???r"jheaderctj|}t||_||dSr)r})rNrrrrRs r rz_NodeReporter._write_contents8j!!!'** Cr"c0|ddS)Nr)rIrNrs r append_passz_NodeReporter.append_passs x     r"c@t|dr|dddS|jJt|jdd}||j}nt |j}t |}|d|t |jdS)Nwasxfailskippedz%xfail-marked test passes unexpectedly reprcrashfailure)rlrlongreprgetattrrzr#r')rNrrrzs r append_failurez_NodeReporter.append_failures 6: & & G   Y(O P P P P P?...4;d55I$#+fo..$W--G   YV_1E1E F F F F Fr"cj|jJ|ddt|jdS)Nerrorzcollection failure)rrr#rs r append_collect_errorz"_NodeReporter.append_collect_errors9*** "6FO8L8LMMMMMr"cX|ddt|jdS)Nrzcollection skipped)rr#rrs r append_collect_skippedz$_NodeReporter.append_collect_skippeds+ $8#fo:N:NOOOOOr"c|jJt|jdd}||j}nt|j}|jdkrd|d}nd|d}|dt |t|jdS)Nrteardownzfailed on teardown with ""zfailed on setup with "r)rrrzr#whenrr')rNrrreasonmsgs r append_errorz_NodeReporter.append_errors***07 O[$1 1   &FF))F ;* $ $7f777CC46444C ."5"5s6?7K7KLLLLLr"c6t|drc|j}|dr |dd}t|}t jdd|}||dSt|jtsJ|j\}}}|dr |dd}|d |d |}t jdd |}t||_ ||| |dS) Nrzreason: rz pytest.xfail)r.rzz Skipped: :z: z pytest.skip) rlr startswithr'r^r_rSr+rtupler~r)rNr xfailreasonrfilenamelineno skipreasondetailss r append_skippedz_NodeReporter.append_skippeds. 6: & & / /K%%j11 .)!""o (55KjUUUG KK fou55 5 55+1? (Hfj$$[11 ,'^ !::F::j::Gj SSSG)'22GL KK  & &v . . . . .r"cv||jfd|_dS)NcSr))r{sr z(_NodeReporter.finalize..sdr")ry__dict__clear)rNr{s @r finalizez_NodeReporter.finalizes7{{}} #lll r"r)rN)__name__ __module__ __qualname__r r#rrOr^r_rSobjectrWrYrrartryrrrrrrrrrrrrr"r rCrCYs(uS*_5(H((((( 2: $    CCVCCCCC6#6f66666hrz&: J 4    < sS QU CJC4CCCC.@@S@S@@@@Z#PT !*!!!!!GZGDGGGG N:N$NNNN PZPDPPPPM:M$MMMM /Z/D////(######r"rCrequest fixture_namecddlm}|jjt d}|H|jdvrA|j|d ||jdSdSdS)z[Emit a PytestWarning about the given fixture being incompatible with newer xunit revisions.r) PytestWarningN)r@legacyzV{fixture_name} is incompatible with junit_family '{family}' (use 'legacy' or 'xunit1'))rrJ) _pytest.warning_typesrconfigstashgetxml_keyrJrPwarnformat)rrrrEs r !_warn_incompatibility_with_xunit2rs433333 .  " "7D 1 1C 3:-AAA  Mhoo!-cjp       AAr"cTtddtdtddffd }|S)anAdd extra properties to the calling test. User properties become part of the test report and are available to the configured reporters, like JUnit XML. The fixture is callable with ``name, value``. The value is automatically XML-encoded. Example:: def test_function(record_property): record_property("example_key", 1) record_propertyr:rTrNcJjj||fdSr))rPuser_propertiesrS)r:rTrs r append_propertyz(record_property..append_property*s& $++T5M:::::r")rr#r)rrs` r rrsQ&g/@AAA;c;&;T;;;;;; r"c>ddlm}|j|dt |ddt dt ddfd }|}|jj td}|&| |jj }|j }|S) zAdd extra xml attributes to the tag for the calling test. The fixture is callable with ``name, value``. The value is automatically XML-encoded. r)PytestExperimentalApiWarningz/record_xml_attribute is an experimental featurerecord_xml_attributer:rTrNcdSr)rr]s r add_attr_noopz+record_xml_attribute..add_attr_noop@s r")rrrPrrr#rrrrr node_reporterrDrY)rrr attr_funcrErs r rr0sCBBBBB L$$%VWW&g/EFFF C  4    I .  " "7D 1 1C ))',*=>> !/ r"paramvcd}t|ts8d}t||t |jdS)zcUsed by record_testsuite_property to check that the given parameter name is of the proper type.Tz5{param} parameter needs to be a string, but {g} given)rgN)r+r#r-rr.r)rr__tracebackhide__rs r _check_record_param_typerMsU a  EE $q''2B CCDDDEEr"session)scopecd}dtdtddfd}|jjt d}||j}|S)a+Record a new ```` tag as child of the root ````. This is suitable to writing global information regarding the entire test suite, and is compatible with ``xunit2`` JUnit family. This is a ``session``-scoped fixture which is called with ``(name, value)``. Example: .. code-block:: python def test_foo(record_testsuite_property): record_testsuite_property("ARCH", "PPC") record_testsuite_property("STORAGE_TYPE", "CEPH") :param name: The property name. :param value: The property value. Will be converted to a string. .. warning:: Currently this fixture **does not work** with the `pytest-xdist `__ plugin. See :issue:`7767` for details. Tr:rTrNc*d}td|dS)zENo-op function in case --junitxml was not passed in the command-line.Tr:N)r)r:rTrs r record_funcz.record_testsuite_property..record_funcss  .....r")r#rrrrradd_global_property)rrrrEs r record_testsuite_propertyrVsb6/#/f///// .  " "7D 1 1C - r"parserc |d}|dddddtjtddd |d d dd dd |ddd|ddd|dddd|ddd|ddd dS)!Nzterminal reportingz --junitxmlz --junit-xmlstorexmlpathpath)optnamez0Create junit-xml style report file at given path)actiondestmetavarr.defaulthelpz --junitprefixz--junit-prefixr#z0Prepend prefix to classnames in junit-xml output)rrrrjunit_suite_namez Test suite name for JUnit reportpytest)r junit_loggingz\Write captured log messages to JUnit report: one of no|log|system-out|system-err|out-err|allrjunit_log_passing_testsz;Capture log information for passing tests to JUnit report: boolT)r.rjunit_duration_reportz*Duration time to report: one of total|calltotal junit_familyz0Emit XML for schema: one of legacy|xunit1|xunit2rA)getgroup addoption functoolspartialraddini)rrs r pytest_addoptionr ~sR OO0 1 1E OO   |\ B B B ?    OO ?  MM> MM :   MM!E    MM4  MM:r"rc |jj}|rt|ds|d}t ||jj|d|d|d||d|jt<|j |jtdSdSdS)N workerinputrrrrr) optionrrlgetinir junitprefixrr pluginmanagerregister)rrrs r pytest_configurersm#G =wv}55 =}}^44 &  M % MM, - - MM/ * * MM1 2 2  MM3 4 4! !  W %%fl7&;<<<<< = = = =r"c|jtd}|r)|jt=|j|dSdSr))rrrr unregister)rrEs r pytest_unconfigurersR ,  7D ) )C - L !'',,,,,--r"addressc|d\}}}|d}|dtjd|d<t jdd|d|d<|dxx||zz cc<|S)N[z::rrez\.py$rrd) partitionsplitreplacer SEPr$r%)rrpossible_open_bracketparamsros r rgrgs*1*;*;C*@*@'D  JJt  EQx 3//E!HvhE!H--E!H "III&//III Lr"c ,eZdZ d!deededed ed ed d f d Zded d fdZde eefd e fdZ ded d fdZ ded e fdZ ded d fdZded d fdZded d fdZded d fdZd"dZd"dZded d fdZdeded d fdZd eejfd Zd S)#rrrrr@Trh suite_namerreport_durationrrNctjtj|}tjtj||_||_||_||_ ||_ ||_ ||_ tgdd|_i|_g|_g|_g|_d|_|j dkr d|_ dSdS)N)rrrrrrr@)osr expanduser expandvarsnormpathabspathlogfilerhr"rrr#rJdictfromkeysstatsnode_reportersnode_reporters_orderedglobal_properties open_reportscnt_double_fail_tests)rNr*rhr"rr#rJrs r rOzLogXML.__init__s'$$RW%7%7%@%@AAw''(@(@AA  $ !2. %)]] 5 5 5q& &   <>#8:/1%&" ;( " ""DKKK # "r"rct|d|}t|dd}|j||f}||dSdSNrDrP)rr.popr)rNrrD workernodereporters r rzLogXML.finalizese622VVT22 &**FJ+?@@           r"ct|d|}t|dd}||f}||jvr |j|St||}||j|<|j||Sr4)rr.rCr/rS)rNrrDr6rsr7s r rzLogXML.node_reporters)06)J)JVVT22 j  $% % %&s+ + ..#+C  #**8444r"rscF||jvr|j|xxdz cc<dSdS)Nrf)r-)rNrss r rIzLogXML.add_statss3 $*   JsOOOq OOOOO  r"cZ||}|||Sr))rrtrNrr7s r _opentestcasezLogXML._opentestcases.%%f--""6***r"cd}jr7jdkr*|}|n1jrjdkrlt ddt ddt fd|jDd}|r%|||xj dz c_ |}jdkrL| |j |j s| nG|n1jr*|}||jdkr|}| jD](\}}||t)|)|t ddt ddt fd|jDd}|r|j|dSdSdS) aHandle a setup/call/teardown report, generating the appropriate XML tags as necessary. Note: due to plugins like xdist, this hook may be called in interlaced order with reports from other nodes. For example: Usual call order: -> setup node1 -> call node1 -> teardown node1 -> setup node2 -> call node2 -> teardown node2 Possible call order in xdist: -> setup node1 -> call node1 -> setup node2 -> call node2 -> teardown node2 -> teardown node1 Ncallr worker_id item_indexc3K|]@}|jjkr.t|ddkrt|ddk<|VAdSr@Nr?rDr.0repr report_ii report_wids r z2LogXML.pytest_runtest_logreport..9soJ&-77 '\4 @ @I M M '[$ ? ?: M M  !N M M M r"rfc3K|]@}|jjkr.t|ddkrt|ddk<|VAdSrBrCrDs r rIz2LogXML.pytest_runtest_logreport..aso fm33#Ct<< II#Cd;;zII  JIII r")rrr<rfailedrnextr1rr2rrSrrrrrupdate_testcase_durationrrWr#remove)rNr close_reportr7propname propvaluerGrHs ` @@r pytest_runtest_logreportzLogXML.pytest_runtest_logreports. =% ,{f$$--f55$$V,,, ]! ,{j(($V[$?? #FL$?? ##'#4    4MM,///..!3..))&11H{f$$''///!((000-;226:::%%f---- ^ ,))&11H  # #F + + + %%f--- ;* $ $))&11H  * *6 2 2 2'-'= @ @#)%%hI???? MM& ! ! ! d;;J d;;I#0  L 7!((66666/ % $, 7 7r"c|jdks|j|jkr6||}|xjt |ddz c_dSdS)zAccumulate total duration for nodeid from given report and update the Junit.testcase with the new total if already created.rrKrGN)r#rrrKrr;s r rMzLogXML.update_testcase_durationosc  7 * *fkT=Q.Q.Q))&11H   S!A!A A    /R.Qr"c|jsJ||}|jr||dS||dSdSr))rr<rKrrr;s r pytest_collectreportzLogXML.pytest_collectreportvsg} 8))&11H} 8--f55555//77777  8 8r"excreprc|d}|jdd|ddt |dS)Ninternalr)r9r:rzinternal error)rrMr/rr#)rNrVr7s r pytest_internalerrorzLogXML.pytest_internalerror~sU%%j11zBBBW&6G EEEEEr"c6tj|_dSr))r rwsuite_start_time)rNs r pytest_sessionstartzLogXML.pytest_sessionstarts & r"c tjtj|j}tj|dt |jdd5}tj}||j z }|j d|j dz|j dz|j d z|j z }| d tjd |jt!|j d t!|j dt!|j dt!|d |zt#j|j t)j }|}||||jD])}||*tjd} | || tj| dddddS#1swxYwYdS)NT)exist_okwzutf-8)encodingrrrrz& testsuiterv)r:errorsfailuresrtestsrw timestamphostname testsuitesunicode)r%rdirnamer)r*makedirsopenr rwr[r-r2writer^r_r"r#r fromtimestamp isoformatplatformrP_get_global_properties_noderSr/rytostring) rNrir*suite_stop_timesuite_time_deltanumtests suite_noder0rrgs r pytest_sessionfinishzLogXML.pytest_sessionfinishst'//"'//$,"?"?@@ Gd++++ $,g 6 6 6 G'$kmmO.1FF  8$*Y'(*Y'(*W%&, -  MMB C C C_4:g.//TZ 233DJy122(mm.."01FGGQQSS!   J!% @ @ B B  ,!!"3444!%!< : : !!-"6"6"8"89999L11J   j ) ) ) MM"+j9EEE F F F? G G G G G G G G G G G G G G G G G Gs/GIIIterminalreportercB|dd|jdS)Nrzgenerated xml file: ) write_sepr*)rNrws r pytest_terminal_summaryzLogXML.pytest_terminal_summarys)""3(Mt|(M(MNNNNNr"r:rTc|d}td||j|t|fdS)NTr:)rr0rSr')rNr:rTrs r rzLogXML.add_global_propertysB  ... %%t^E-B-B&CDDDDDr"c|jrMtjd}|jD]/\}}|tjd||0|SdSr[)r0r^r_rSr`s r rpz"LogXML._get_global_properties_nodesg  ! L11J#5 R R e!!"*Zd%"P"P"PQQQQ tr")rrrr@Tr)rrrrr#rrOrrr rCrrIr<rRrMrUr rYr\rvrrzrrr^r_rprr"r rrsS #&"&!#!# !# !#  !#  !# !# !#!#!#!#F z d    E*c/$:}$!S!T!!!!J= V7zV7dV7V7V7V7pBzBdBBBB8:8$8888FMFdFFFF ....$G$G$G$GLO8HOTOOOOEEFEtEEEE Xbj-Ar"r)9__doc__r r%ror$xml.etree.ElementTreeetree ElementTreer^rtypingrrrrrr r r_pytestr r _pytest._code.coder r_pytest.configrr_pytest.config.argparsingr_pytest.fixturesr_pytest.reportsr _pytest.stashr_pytest.terminalrrrr#r'r7rncopyrCrfixturerrrrr rrrgrrr"r rs  """"""""" ,,,,,,//////!!!!!!'''''',,,,,,++++++&&&&&&""""""------ (8   22322226 +v!67&(?(?(?@g&++-- Xh .!9:::g&l#l#l#l#l#l#l#l#^  +.      "^#v9L0M,.XsFmT>Q5R8ECECEDEEEEi   $~$(C=RVCV:W$$$! $N,V,,,,,^=V====="-v-$----ckkkkkkkkkkr"