bg dZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddl#m$Z$ddl%m&Z&ddl%m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl.m0Z0ddl.m1Z1ddl2m3Z3ddl2m4Z4dd l2m5Z5dd!l2m6Z6dd"l2m7Z7dd#l2m8Z8dd$l9m:Z:dd%l;mZ>dd'l=m?Z?dd(l@mAZAdd)lBmCZCdd*lDmEZEdd+lDmFZFdd,lGmHZHdd-lGmIZIdd.lGmJZJdd/lKmLZLdd0lKmMZMdd1lKmNZNdd2lOmPZPdd3lOmQZQdd4lRmSZSdd5lTmUZUe!rdd6lVmWZWdd7lVmXZXddlYZYd8gZZd9gZ[d:e:d;dfd<Z\d=e4d;dfd>Z]Gd?d@Z^e>dAe?d;dBfdCZ(GdDdBZ_dEee`d;ee`fdFZae/GdGdHZbe/GdIdJZce>dddLZde>dMNdAe?d;e dMfdOZee>dAe?dPeSdQeCd;dRfdSZfe>d;edTfdUZge>d;ee4ddffdVZhe jidWZje jidXZke/GdYdZZlGd[d\ZmGd]d^ZnGd_d`Zoe/GdadRZpGdbdKZqGdcdMZrdS)ezZ(Disabled by default) support for testing pytest and pytest plugins. PYTEST_DONT_REWRITE N)fnmatch)StringIO)Path)Any)Callable)Dict) Generator)IO)Iterable)List)Optional)overload)Sequence)TextIO)Tuple)Type) TYPE_CHECKING)Union)WeakKeyDictionary) IniConfig)SectionWrapper)timing)Source)_get_multicapture)final)NOTSET) NotSetType) _PluggyPlugin)Config)ExitCode)hookimpl)main)PytestPluginManager)Parser)check_ispytest)fixture)FixtureRequest)Session) MonkeyPatch) Collector)Item)fail) importorskip)skip) bestrelpath)copytree)make_numbered_dir) CollectReport) TestReport)TempPathFactory) PytestWarning)Final)Literalpytester_assertionsz/var/lib/sss/mc/passwdparserreturnc|ddddd|ddd d d |d ddS)Nz--lsof store_truelsofFz"Run FD checks if lsof is available)actiondestdefaulthelp --runpytest inprocess runpytest)rC subprocesszYRun pytest sub runs in tests using an 'inprocess' or 'subprocess' (python -m main) method)r@r?choicesrApytester_example_dirz1Directory to take the pytester example files from)rA) addoptionaddini)r9s a/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/_pytest/pytester.pypytest_addoptionrKWs   1   + 6     MM%Xconfigc|dr.isopensL??3''%&%&%&%  rL r/)rErunstrosgetpidPIPEDEVNULLlocalegetpreferredencodingr[boolsplit IGNORE_PAMrhappend)selfoutri open_filesr`fieldsfdfilenames rJget_open_filesz LsofFdLeakChecker.get_open_files~s!n WdC $4$4 5?%077             IIdOO 6 6Dvd|| 6D))AYqrr]!!9QRR=z))&&s++6%%r8n555rLcn tjdddS#ttjf$rYdSwxYw)N)r=z-vT)r]F)rErnOSErrorCalledProcessErrorrzs rJrRz#LsofFdLeakChecker.matching_platformsO  N> 6 6 6 6467   55 s 44T) hookwrappertryfirstitemNNNc#&K|}dVttdrtj|}d|Dd|Dz fd|D}|rdt |zgd|Ddd|Dd d |Ddt |zd |jzd }|td |dSdS)Npypy_version_infoch|] }|d Sr.0ts rJ z.s(((A1Q4(((rLch|] }|d Srrrs rJrz.s+A+A+AQAaD+A+A+ArLc(g|]}|dv |Srr)rrnew_fdss rJ z=LsofFdLeakChecker.pytest_runtest_protocol..s"===aQqTW_____rLz***** %s FD leakage detectedc34K|]}t|VdSNrorrbs rJ z.s(//Q#a&&//////rLz *** Before:c34K|]}t|VdSrrrs rJrz.())Q#a&&))))))rLz *** After:c34K|]}t|VdSrrrs rJrz.rrLz*** function %s:%s: %s zSee issue #2366rj) rhasattrsysgccollectlenlocationwarnr5join)rzrlines1lines2 leaked_fileserrorrs @rJpytest_runtest_protocolz)LsofFdLeakChecker.pytest_runtest_protocolss$$&&  3+ , ,  JLLL$$&&(((((+A+A&+A+A+AA====6===  7.\1B1BB //,///  *)&)))    *)&))) /\1B1BB *DM9 " E IImDIIe$4$455 6 6 6 6 6 7 7rLN) __name__ __module__ __qualname__r rrorrvrRr!r+r rrrLrJrQrQ}sU38_ 5@4X$...7D7Y?O5P777/.777rLrQrequest PytestArgc t|S)zReturn a helper which offers a gethookrecorder(hook) method which returns a HookRecorder instance which helps to make assertions about called hooks.)rrs rJ_pytestrs W  rLc&eZdZdeddfdZddZdS)rrr:Nc||_dSr)_request)rzrs rJ__init__zPytestArg.__init__s  rL HookRecorderclt|j}|j|j|Sr)r_pmr addfinalizerfinish_recording)rzhook hookrecorders rJgethookrecorderzPytestArg.gethookrecorders0#DH--  ""<#@AAArL)r:r)rrrr'rrrrLrJrrsJ  4    rLvaluescd|DS)zDOnly return names from iterator values without a leading underscore.c*g|]}|ddk|S)r_rrxs rJrz$get_public_names..s! - - -!1ArLr)rs rJget_public_namesrs - -v - - --rLcBeZdZdZdeddfdZdefdZerdefdZdSdS) RecordedHookCalla;A recorded call to a hook. The arguments to the hook call are set as attributes. For example: .. code-block:: python calls = hook_recorder.getcalls("pytest_runtest_setup") # Suppose pytest_runtest_setup was called once with `item=an_item`. assert calls[0].item is an_item namer:NcH|j|||_dSr)__dict__update_name)rzrkwargss rJrzRecordedHookCall.__init__s# V$$$ rLcV|j}|d=d|jd|dS)Nrz)rcopyr)rzds rJ__repr__zRecordedHookCall.__repr__s7 M    gJ.before s* J  .y&AA B B B B BrLcdSrr)outcomerrrs rJafterz$HookRecorder.__init__..after s DrL)r%_pluginmanagerrretroadd_hookcall_monitoring_undo_wrapping)rzrSrrrs` rJrzHookRecorder.__init__s y!!!+-/ 37 Cc C$ C C C C C C c $    ,CCFERRrLc.|dSr)rrs rJrzHookRecorder.finish_recordings rLnamesc|ttrfd|jDS)z?Get all recorded calls to hooks with the given names (or name).c&g|] }|jv |Sr)r)rcallrs rJrz)HookRecorder.getcalls..s%CCCtzU/B/B/B/B/BrL) isinstancerorwrrzrs `rJgetcallszHookRecorder.getcallss> eS ! ! "KKMMECCCCCCCCrLentriesc$d}d}t|}tjdj}|r|d\}}t |j|dD]\}}|j|krqtd||t|||j r tdt|d|n tdt|d|w||dzz }n(td |d |td |d ||dSdS) NTrrl NAMEMATCH CHECKERMATCHz->NOCHECKERMATCH- NONAMEMATCHwithzcould not find z check ) listr _getframef_localspop enumeraterrprintevalrreprr,) rzr__tracebackhide__i backlocalsrr]indrs rJassert_containszHookRecorder.assert_containssH  w--]1%%.  A!++a..KD%&tz!""~66 A A T:%%+tT222E:t}==!nd5kk4FFFF.U S$GGG qLAEmT648888?t??e??@@@ A A A A ArLrcd}t|jD]\}}|j|kr |j|=|cSd|dg}|d|jDt d|dS)NTzcould not find call z, in:cg|]}d|zS)z %srrs rJrz(HookRecorder.popcall..6s555Qfqj555rLrj)rrrextendr,r)rzrrrrliness rJpopcallzHookRecorder.popcall/s  ,,  GAtzT!!JqM "65556 55$*555666 TYYu  rLcz||}t|dks J||f|dS)Nrlr)rr)rzrrs rJgetcallzHookRecorder.getcall9s@t$$6{{a$ayrLzLiteral['pytest_collectreport']cdSrrrs rJ getreportszHookRecorder.getreports@ rLz#Literal['pytest_runtest_logreport']cdSrrrs rJr zHookRecorder.getreportsGr rLpytest_collectreportpytest_runtest_logreportcdSrrrs rJr zHookRecorder.getreportsN  rLc@d||DS)Ncg|] }|j Sr)reportrs rJrz+HookRecorder.getreports.._s777Q777rL)rrs rJr zHookRecorder.getreportsXs$87$--"6"67777rLrr inamepartwhencg}||D]X}|s|jdkr|jr|r |j|kr%|r||jdvr||Y|st d|dt|dkr#t d|||dS) z5Return a testreport whose dotted import path matches.)rr::z$could not find test report matching z: no test reports at all!rlz-found 2 or more testreports matching {!r}: {}r) r rpassednodeidrwry ValueErrorrformat)rzrrrrreps rJ matchreportzHookRecorder.matchreportas???// # #C CH..3:. D(( # SZ-=-=d-C-C C C c""" *-6YY9  v;;???FFv  ayrLcdSrrrs rJ getfailureszHookRecorder.getfailuresr rLcdSrrrs rJr#zHookRecorder.getfailuresr rLcdSrrrs rJr#zHookRecorder.getfailuresrrLc@d||DS)Nc g|] }|j | Sr)failed)rr s rJrz,HookRecorder.getfailures..sDDDDDDDrL)r rs rJr#zHookRecorder.getfailuress%EDtu55DDDDrLc,|dS)Nr)r#rs rJgetfailedcollectionsz!HookRecorder.getfailedcollectionss 6777rLcRg}g}g}|dD]}|jr8|jdkr,t|tsJ||A|jr||^|js Jd||||||fS)NrrzUnexpected outcome: )r rrrr3ryskippedr()rzrr,r(r s rJ listoutcomeszHookRecorder.listoutcomess?? @  # #Cz #8v%%%c:66666MM#&&& #s####zAA#A##A#AAAz c""""w&&rLc>d|DS)Nc,g|]}t|Sr)rrs rJrz.HookRecorder.countoutcomes..s4441A444rL)r-rs rJ countoutcomeszHookRecorder.countoutcomess"44 1 1 3 34444rLrrr,r(c\d}ddlm}|}|||||dS)NTr) assertoutcome)rr,r()_pytest.pytester_assertionsr2r-)rzrr,r(rr2outcomess rJr2zHookRecorder.assertoutcomesZ ======$$&&        rLcg|jdd<dSr)rrs rJclearzHookRecorder.clears 111 rLr:N)r)rrN)rrr) rrrrr#rvrrrror r rrrrrrr rr2r r3r r!r#r*r-intr0r2r6rrLrJrrsHMSSS0S@DS SSSS"DeC#$67DDAQ)rrr[rr\rUrs rJrzRunResult.__repr__)s: YxT[.//T[5F1G1GW X rLc6||jS)aUReturn a dictionary of outcome noun -> count from parsing the terminal output that the test process produced. The returned nouns will always be in plural form:: ======= 1 failed, 1 passed, 1 warning, 1 error in 0.13s ==== Will return ``{"failed": 1, "passed": 1, "warnings": 1, "errors": 1}``. )parse_summary_nounsrSrs rJ parseoutcomeszRunResult.parseoutcomes/s'' 666rLct|D]D}t|r(t|}d|D}nEt ddddfd|DS)aExtract the nouns from a pytest terminal summary line. It always returns the plural noun for consistency:: ======= 1 failed, 1 passed, 1 warning, 1 error in 0.13s ==== Will return ``{"failed": 1, "passed": 1, "warnings": 1, "errors": 1}``. c4i|]\}}|t|Sr)r8)rcountnouns rJ z1RunResult.parse_summary_nouns..Hs$FFFMUDtSZZFFFrLz(Pytest terminal summary report not foundwarningserrors)warningrcDi|]\}}|||Sr)get)rkv to_plurals rJr_z1RunResult.parse_summary_nouns..Qs-???41a a##Q???rL)reversedrex_session_durationsearch rex_outcomefindallritems)clsrr`r4rrgs @rJrYzRunResult.parse_summary_nouns;sUOO I ID#**400 &..t44FFXFFF  GHH H"  @???399;;????rLrrr,r(raxpassedxfailedr` deselectedc fd} ddlm} |} | | |||||||| dS)z Assert that the specified outcomes appear with the respective numbers (0 means it didn't occur) in the text output from a test run. ``warnings`` and ``deselected`` are only checked if not None. Tr)assert_outcomes)rr,r(rarorpr`rqN)r3rsrZ) rzrr,r(rarorpr`rqrrsr4s rJrszRunResult.assert_outcomesSsk"!??????%%'' ! rL)rrrrrrNN)rrrrrr8r r rofloatrrrrZ classmethodrYr rsrrLrJrRrR stII# 3= !#s)#s) #  #  ####6 #    7tCH~ 7 7 7 7@4S>@@@[@2"&$(           3- SM        rLrRceZdZddZddZdS) CwdSnapshotr:Nc6tj|_dSr)rpgetcwd_CwdSnapshot__savedrs rJrzCwdSnapshot.__init__vsy{{ rLc8tj|jdSr)rpchdirrzrs rJrHzCwdSnapshot.restoreys rLr7rrrrrHrrLrJrwrwus<####rLrwcFeZdZddeeegefddfdZddZdS)rGNpreserver:cP||_ttj|_dSr)_SysModulesSnapshot__preservedictrmodules_SysModulesSnapshot__saved)rzrs rJrzSysModulesSnapshot.__init__~s"CK(( rLcjrBjfdtjDtjtjjdS)Nc3PK|] \}}|||fV!dSr)r)rremrzs rJrz-SysModulesSnapshot.restore..sP  1a$//!:L:L A      rL)rrrrrrmr6rs`rJrHzSysModulesSnapshot.restores ?  L      #&;#4#4#6#6        4<(((((rLrr7) rrrr rrorvrrHrrLrJrGrG}s_))(C5$;*?!@)D))))))))))rLrGceZdZddZddZdS)rFr:Nctttjttjf|_dSr)rrpath meta_path_SysPathsSnapshot__savedrs rJrzSysPathsSnapshot.__init__s$CH~~tCM':':: rLcV|j\tjdd<tjdd<dSr)rrrrrs rJrHzSysPathsSnapshot.restores)(, % S]111%%%rLr7r}rrLrJrFrFs<;;;;555555rLrFc "eZdZUdZdZeZded<GddeZ ddde d e d e d e d d f dZed efdZd efdZd`dZd efdZded efdZd`dZ dadedeeeefdeeefded ef dZ dededed efdZ!ded efd Z"ded efd!Z#ded e$fd"Z%ded efd#Z&d efd$Z'd efd%Z( dbd&e)eed'fd d fd(Z*d)eed'fd efd*Z+d)eed'fd efd+Z,dbd)e)ed efd,Z-d-e.d.eed'fd ee/e0ffd/Z1d&eed'fd ee/e0ffd0Z2d1eee0e/fd e3e0fd2Z4ded efd3Z5ded efd4Z6d e7e3e0effd5Z8d6dd7deed'fd8e d efd9Z9deed'fded e:fd:Z;deed'fded e:fd;Zdeed'fd e.fd>Z? dcdeed'fd@ed e0fdAZ@deed'fd e3e0fdBZA ddddCdeed'fdDe fdEZBdFe/d)ed e)ee0e/ffdGZCeDjEeDjEefdHeeed'fdIeeFeGfdJeeFeGfdKeeHeeIeeFffdLZJd edMdHeed'fdNe)eKdKeeHeeIeeFfd e:fdOZLdPZMd e7edQffdRZNdSd'd e:fdTZOdUed e:fdVZPd dWdeed'fdNe)eKd e:fdXZQ dedZed[eKd d\fd]ZRded^ed[eKd d\fd_ZSd S)frBan Facilities to write tests/configuration files, execute pytest in isolation, and match against expected output, perfect for black-box testing of pytest plugins. It attempts to isolate the test run from external factors as much as possible, modifying the current working directory to :attr:`path` and environment variables during initialization. Fr6 CLOSE_STDINceZdZdS)Pytester.TimeoutExpiredNrrrrrLrJTimeoutExpiredrs rLrrrr@rArr:Nct|||_t|_|jr |jj}n |jj}||_| |d|_ g|_ t|_ t|_||_||j|j|jjd|_| d|d|_|x|_}|dt7|j|dd|d dt7|j}|d ||d ||d d dS)NT)numberedrBztmp-PYTEST_DEBUG_TEMPROOT TOX_ENV_DIRF)raisingPYTEST_ADDOPTSHOME USERPROFILE PY_COLORS0)r%rr_mod_collectionsfunctionrnoderrmktemp_pathpluginsrw _cwd_snapshotrF_sys_path_snapshot$_Pytester__take_sys_modules_snapshot_sys_modules_snapshotr|r _finalizerM getoption_method _test_tmproot _monkeypatchsetenvrodelenvr)rzrr@rArrmptmphomes rJrzPytester.__init__s y!!!        %(1DD<$D +224$2GG 9; (]]"2"4"4%)%E%E%G%G"  ""4>222}+55mDD -44]D]]T4RR!,,B )3t/A+B+BCCC - /// "E 222di.. &'""" -))) +s#####rLc|jS)zBTemporary directory path used to create files/run tests from, etc.)rrs rJrz Pytester.paths zrLcd|jdS)Nz )rrs rJrzPytester.__repr__s*DI****rLc|j|j|jdS)a Clean up global state artifacts. Some methods modify the global interpreter state and this tries to clean this up. It does not remove the temporary directory however so it can be looked at after the test run has finished. N)rrHrrrs rJrzPytester._finalizesI "**,,, ''))) ""$$$$$rLc(d}t|S)Nc,|dS)N)zopereadlinergr=s rJpreserve_modulez=Pytester.__take_sys_modules_snapshot..preserve_modules??#788 8rL)r)rG)rzrs rJ__take_sys_modules_snapshotz$Pytester.__take_sys_modules_snapshots$ 9 9 9"?;;;;rLrSctt|dx|_}|j|j|S)zFCreate a new :class:`HookRecorder` for a :class:`PytestPluginManager`.Tr)rreprecrrr)rzrSrs rJmake_hook_recorderzPytester.make_hook_recorders:(4]d(S(S(SS v ""6#:;;; rLc8tj|jdS)zaCd into the temporary directory. This is done automatically upon instantiation. N)rpr|rrs rJr|zPytester.chdirs rLutf-8extrfilesr_c t|}|r*|dstd|d|dtt t fdtffd |r@d fd|D}|j }| d ||fd}|D]\}} |j | |} | jd d t!| } d fd | jD}| | || }|J|S)N.z1pytester.makefile expects a file extension, try .z instead of sr:cvt|tr|nt|Sr)rbytesdecodero)rr_s rJto_textz#Pytester._makefile..to_text s/)3Au)=)=I188H%%%3q66 IrLrjc3.K|]}|VdSrr)rrrs rJrz%Pytester._makefile..s+99awwqzz999999rLrT)parentsexist_okc3.K|]}|VdSrr)rr`rs rJrz%Pytester._makefile..s+GGwwt}}GGGGGGrLr_)rrmrhrrrrrorrinsertrjoinpath with_suffixparentmkdirrr write_textstrip) rzrrrr_rmsourcebasenamervaluepsource_rs ` @rJ _makefilezPytester._makefilesU[[]]##  s~~c** ZCZZUXZZ  JuS%Z( JS J J J J J J  0YY9999599999FzH LLXv. / / /$  OHe ""8,,88==A HNN4$N 7 7 7UmmGYYGGGGGGGGGF LL(L ; ; ;{ rLargsrc0||||S)aCreate new text file(s) in the test directory. :param ext: The extension the file(s) should use, including the dot, e.g. `.py`. :param args: All args are treated as strings and joined using newlines. The result is written as contents to the file. The name of the file is based on the test function requesting this fixture. :param kwargs: Each keyword is the name of a file, while the value of it will be written as contents of the file. :returns: The first created file. Examples: .. code-block:: python pytester.makefile(".txt", "line1", "line2") pytester.makefile(".ini", pytest="[pytest]\naddopts=-rs\n") To create binary files, use :meth:`pathlib.Path.write_bytes` directly: .. code-block:: python filename = pytester.path.joinpath("foo.bin") filename.write_bytes(b"...") r)rzrrrs rJmakefilezPytester.makefile s<~~c4000rLrc.||S)zoWrite a contest.py file. :param source: The contents. :returns: The conftest.py file. )conftest) makepyfilerzrs rJ makeconftestzPytester.makeconftest@s ///rLc0|d|S)zhWrite a tox.ini file. :param source: The contents. :returns: The tox.ini file. z.ini)toxrrs rJmakeinizPytester.makeiniHs }}V}000rLcp||}tt|dS)z7Return the pytest section from the tox.ini config file.pytest)rrro)rzrrs rJ getinicfgzPytester.getinicfgPs, LL Q  **rLc0|d|S)zWrite a pyproject.toml file. :param source: The contents. :returns: The pyproject.ini file. .. versionadded:: 6.0 z.toml) pyprojectrrs rJmakepyprojecttomlzPytester.makepyprojecttomlUs}}W}777rLc0|d||S)aSShortcut for .makefile() with a .py extension. Defaults to the test name with a '.py' extension, e.g test_foobar.py, overwriting existing files. Examples: .. code-block:: python def test_something(pytester): # Initial file is created test_something.py. pytester.makepyfile("foobar") # To create multiple files, pass kwargs accordingly. pytester.makepyfile(custom="foobar") # At this point, both 'test_something.py' & 'custom.py' exist in the test directory. .pyrrzrrs rJrzPytester.makepyfile_s$~~eT6222rLc0|d||S)a[Shortcut for .makefile() with a .txt extension. Defaults to the test name with a '.txt' extension, e.g test_foobar.txt, overwriting existing files. Examples: .. code-block:: python def test_something(pytester): # Initial file is created test_something.txt. pytester.maketxtfile("foobar") # To create multiple files, pass kwargs accordingly. pytester.maketxtfile(custom="foobar") # At this point, both 'test_something.txt' & 'custom.txt' exist in the test directory. z.txtrrs rJ maketxtfilezPytester.maketxtfiless$~~fdF333rLrzos.PathLike[str]cf||j}|jt|dS)zPrepend a directory to sys.path, defaults to :attr:`path`. This is undone automatically when this object dies at the end of each test. :param path: The path. N)rrsyspath_prependro)rzrs rJ syspathinsertzPytester.syspathinserts3 <9D ))#d))44444rLrcB|j|z }||S)zCreate a new (sub)directory. :param name: The name of the directory, relative to the pytester path. :returns: The created directory. )rrrzrrs rJrzPytester.mkdirs" I   rLc|j|z }||d|S)zCreate a new python package. This creates a (sub)directory with an empty ``__init__.py`` file so it gets recognised as a Python package. __init__.py)rrrtouchrs rJmkpydirzPytester.mkpydirs@ I    =!!'')))rLc@|jjd}|td|jjj|z }|jjdD]}|jsJ|j|j}|V|j }||z }||dzz }| r|}n@| r|}n)t|d|||}| rC|d st||j|jS| r6|j|j} t!j|| | Std|d ) zCopy file from project's directory into the testdir. :param name: The name of the file to copy. :return: Path to the copied directory (inside ``self.path``). rGNz2pytester_example_dir is unset, can't copy examplespytester_example_pathrz( can't be found as module or package in rz example "z%" is not found as a file or directory)rrMgetinirrootpathr iter_markersrrris_diris_file LookupErrorr0rrshutilr) rzr example_dir_ example_dir extra_element func_name maybe_dir maybe_file example_pathresults rJ copy_examplezPytester.copy_examples}+223IJJ  QRR R M09LH !]/<<=TUU D DM % % %%.+. 0BCKK < I#i/I$ E(9:J!! ( ##%% ) ! WW+WW'//55L    )>)>})M)M)U)U)W)W  \49 - - -9   ! ! # # Y'' (9::F K f - - -MOLOOO rLrMargctj|}dt|vsJttj|}|j|| t|gdd}|j |tj |S)aGet the collection node of a file. :param config: A pytest config. See :py:meth:`parseconfig` and :py:meth:`parseconfigure` for creating it. :param arg: Path to the file. :returns: The node. rsessionFgenitemsrr exitstatus) r( from_configrorrprabspathrpytest_sessionstartperform_collectpytest_sessionfinishr OK)rzrMrrrress rJgetnodezPytester.getnodes%f--3s88#### %% & & '''888%%s1vvh%??B ((X[(QQQ rLc^t|}||}tj|}t |j|}|j|||gdd}|j |tj |S)aReturn the collection node of a file. This is like :py:meth:`getnode` but uses :py:meth:`parseconfigure` to create the (configured) pytest Config instance. :param path: Path to the file. :returns: The node. rFrrr) rparseconfigurer(rr/rrrrrr r)rzrrMrrrs rJ getpathnodezPytester.getpathnodesDzz$$T**%f--  d + + '''888%%qcE%::1= ((X[(QQQ rLcolitemsc~|dj}g}|D]*}|||+|S)aGenerate all test items from a collection node. This recurses into the collection node and returns a list of all the test items contained within. :param colitems: The collection nodes. :returns: The collected items. r)rrr)rzr!rr colitems rJrzPytester.genitemssL1+% 5 5G MM'**733 4 4 4 4 rLc||}|jj}|}||S)a'Run the "test_func" Item. The calling test instance (class containing the test method) must provide a ``.getrunner()`` method which should return a runner which can run the test protocol for a single item, e.g. :py:func:`_pytest.runner.runtestprotocol`. )getitemrinstance getrunner)rzrrtestclassinstancerunners rJrunitemzPytester.runitems?||F## M2",,..vd||rLcf||}t||gz}|j|S)agRun a test module in process using ``pytest.main()``. This run writes "source" into a temporary file and runs ``pytest.main()`` on it, returning a :py:class:`HookRecorder` instance for the result. :param source: The source code of the test module. :param cmdlineargs: Any extra command line arguments to use. )rr inline_run)rzr cmdlineargsrrs rJinline_runsourcezPytester.inline_runsource&s8 OOF # #k""aS(t''rLcd|jdg|R}d|dD}||fS)a!Run ``pytest.main(['--collectonly'])`` in-process. Runs the :py:func:`pytest.main` function to run all of pytest inside the test process itself like :py:meth:`inline_run`, but returns a tuple of the collected items and a :py:class:`HookRecorder` instance. z--collect-onlycg|] }|j Sr)rrs rJrz,Pytester.inline_genitems..<sFFFAFFFrLpytest_itemcollected)r,r)rzrrecrms rJinline_genitemszPytester.inline_genitems4sHdo.6666FF.D!E!EFFFczrLr)rno_reraise_ctrlcr4c tjt|}g} |j|t jg G fdd}||td|D|}t dkr }n Gdd}||_ |tj krB|s@| d}|r)|d jjt krt!||D] } |  S#|D] } |  wxYw) aRun ``pytest.main()`` in-process, returning a HookRecorder. Runs the :py:func:`pytest.main` function to run all of pytest inside the test process itself. This means it can return a :py:class:`HookRecorder` instance which gives more detailed results from that run than can be done by matching stdout/stderr from :py:meth:`runpytest`. :param args: Command line arguments to pass to :py:func:`pytest.main`. :param plugins: Extra plugin instances the ``pytest.main()`` instance should use. :param no_reraise_ctrlc: Typically we reraise keyboard interrupts from the child run. If True, the KeyboardInterrupt exception is captured. c&eZdZdeddffd ZdS)$Pytester.inline_run..CollectrMr:Ncb|jdSr)ryrrS)rrMr2rzs rJrWz5Pytester.inline_run..Collect.pytest_configurems,JJt66v7KLLMMMMMrL)rrrrrW)r2rzsrJCollectr7lsQNN4NNNNNNNNNrLr9c,g|]}t|Srrrs rJrz'Pytester.inline_run..qs---1A---rL)rrlceZdZdS)#Pytester.inline_run..reprecNrrrLrJrr<vsDrLrpytest_keyboard_interrupt) importlibinvalidate_cachesrryrrHrFr"rrrr INTERRUPTEDrexcinfotypeKeyboardInterrupt) rzrr4r finalizersr9rrr finalizerr2s ` @rJr,zPytester.inline_run?s2 #%%%w-- (    d>>@@H I I I   .008 9 9 9C N N N N N N N N N N N NN7799 % % %-----w???C3xx1}}FJh***3C*(CDD.U2Y.37HHH+---'     Z     s D+E##E4ch|dd}|r|tj}t d}| |j|i|}n#t$rP}|jd} t|jd}n#t$rYnwxYwGdd}Yd}~n3d}~wt$r#tj Gdd}YnwxYw|\} } |t j| t j| nn#|\} } |t j| t j| wxYw|jJt+|j| | tj|z } || _| S) ztReturn result of running pytest in-process, providing a similar interface to what self.runpytest() provides.rFrrceZdZeZdS),Pytester.runpytest_inprocess..reprecN)rrrrrrLrJrrIsCCCrLrNc$eZdZedZdS)rIN)rrrr rrrLrJrz,Pytester.runpytest_inprocess..reprecs"(1++CCCrL)rrrtimerstart_capturingr, SystemExitrr r Exception traceback print_exc readouterrstop_capturingrr[writer\rrR splitlinesr) rzrrrnowcapturererr{errrs rJrunpytest_inprocesszPytester.runpytest_inprocesss  ?E::  !    kmm#E**!!! " &($9&99   fQi"16!9--CC!D & & &#%%%&&&&&&&&&& &))++HC  " " $ $ $ J  S ! ! ! J  S ! ! ! !))++HC  " " $ $ $ J  S ! ! ! J  S ! ! ! !z%%% J((#..*:*:FKMMC.G.G .S.SS T T TrLcddl}||}d|D}|j||j}|j|j|S)aReturn a new pytest :class:`pytest.Config` instance from given commandline args. This invokes the pytest bootstrapping code in _pytest.config to create a new :py:class:`pytest.PytestPluginManager` and call the :hook:`pytest_cmdline_parse` hook to create a new :class:`pytest.Config` instance. If :attr:`plugins` has been populated they should be plugin modules to be registered with the plugin manager. rNc,g|]}t|Srrrs rJrz(Pytester.parseconfig..s---qCFF---rL)rNr\rM_prepareconfigrrrrO)rzrrr_rMs rJ parseconfigzPytester.parseconfigso ((..--H---..xFF ""6#=>>> rLcB|j|}||S)zReturn a new pytest configured Config instance. Returns a new :py:class:`pytest.Config` instance like :py:meth:`parseconfig`, but also calls the :hook:`pytest_configure` hook. )rf _do_configure)rzrrMs rJrzPytester.parseconfigures*"!4( rL test_funcfuncnamec||}|D]}|j|kr|cSJd|||)aReturn the test item for a test function. Writes the source to a python file and runs pytest's collection on the resulting module, returning the test item for the requested function name. :param source: The module source. :param funcname: The name of the test function for which to return a test item. :returns: The test item. rz+{!r} item not found in module: {} items: {})getitemsrr)rzrrjrmrs rJr%zPytester.getitemsj  f%%  DyH$$ % AHH fe    qrLcX||}||gS)zReturn all test items collected from the module. Writes the source to a Python file and runs pytest's collection on the resulting module, returning all test items contained within. ) getmodulecolr)rzrmodcols rJrlzPytester.getitemss+ ""6**}}fX&&&rL)withinitrpcPt|tjr'|j|}|r Jdn#|jt |i}|jdi|}|r|d|j|g|Rx|_ }| ||S)a*Return the module collection node for ``source``. Writes ``source`` to a file using :py:meth:`makepyfile` and then runs the pytest collection on it, returning the collection node for the test module. :param source: The source code of the module to collect. :param configargs: Any extra arguments to pass to :py:meth:`parseconfigure`. :param withinit: Whether to also write an ``__init__.py`` file to the same directory to ensure it is a package. znot supported for paths#)rr) rrpPathLikerrrrorrrMr)rzr configargsrprkwrMs rJrnzPytester.getmodulecol s. fbk * * )9%%f--D : :!: : :< :*c&kk*B"4?((R((D  * OOSO ) ) )2t24E*EEEE f||FD)))rLroc||jvr)t||j|<|j|D]}|j|kr|cSdS)a.Return the collection node for name from the module collection. Searches a module collection node for a collection node matching the given name. :param modcol: A module collection node; see :py:meth:`getmodulecol`. :param name: The name of the node to return. N)rrrr)rzrorr#s rJcollect_by_namezPytester.collect_by_name/sh . . .,01A1A,B,BD !& ),V4  G|t##$trLcmdargsr[r\stdinc rtj}tjt dtj|ddg|d<||d<||jurtj |d<n*t|trtj |d<n||d<tj |f||d|}||jur#|jJ|jn8t|tr#|jJ|j||S)zInvoke :py:class:`subprocess.Popen`. Calls :py:class:`subprocess.Popen` making sure the current working directory is in ``PYTHONPATH``. You probably want to use :py:meth:`run` instead. N PYTHONPATHrenvry)r[r\)rpenvironrpathseprfilterryrdrrErrrrPopenrycloserT)rzrxr[r\ryrur|popens rJrzPytester.popenAs0jooJOO 4")++sww|R'@'@A B B  L5 D$ $ $$/BwKK u % % $/BwKKBwK MMM"MM D$ $ $;*** K       u % % %;*** K  e $ $ $ rL)timeoutryrc d}tdDjd}jd}tdgRtdt j|dd 5}|dd 5}tj} |||tj d k j j dfd } } n6 } n#tj$r | YnwxYwd d d n #1swxYwYd d d n #1swxYwY|d 5}|d 5}|} |} d d d n #1swxYwYd d d n #1swxYwY| tj| tjt-jt05t3| } d d d n #1swxYwYt5| | | tj| z S)aRun a command with arguments. Run a process using :py:class:`subprocess.Popen` saving the stdout and stderr. :param cmdargs: The sequence of arguments to pass to :py:class:`subprocess.Popen`, with path-like objects being converted to :py:class:`str` automatically. :param timeout: The period in seconds after which to timeout and raise :py:class:`Pytester.TimeoutExpired`. :param stdin: Optional standard input. - If it is :py:attr:`CLOSE_STDIN` (Default), then this method calls :py:class:`subprocess.Popen` with ``stdin=subprocess.PIPE``, and the standard input is closed immediately after the new command is started. - If it is of type :py:class:`bytes`, these bytes are sent to the standard input of the command. - Otherwise, it is passed through to :py:class:`subprocess.Popen`. For further information in this case, consult the document of the ``stdin`` parameter in :py:class:`subprocess.Popen`. :returns: The result. Tc3>K|]}tj|VdSr)rpfspath)rrs rJrzPytester.run..s*::3 #::::::rLr[r\zrunning:z in:wutf8rwin32)ryr[r\ close_fdsNr:cd}d}|)NTz3{seconds} second timeout expired running: {command})secondscommand)rkillwaitr)rtimeout_messagerxrrzrs rJhandle_timeoutz$Pytester.run..handle_timeoutsT$(!!!'!I!I   ))/:::rLr7)tuplerrrrrfopenrrLrrplatformryrrrErreadrU _dump_linesr[r\ contextlibsuppressrr rR)rzrryrxrp1p2f1f2rVrrr{rYrs`` ` @rJrnz Pytester.rungsF!::'::::: Y   ) ) Y   ) ) j#7#### j$(**%%% WWS6W * * %b"''#'2O2O %SU+--CJJ<72 E{& !!### ; ; ; ; ; ; ; ; ;jjll%**W--CC!0%%%"N$$$$$%; % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %@WWfW % % )RWWfW-E-E )''))&&((C''))&&((C ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) cj))) cj)))   , ,  3--C               c3 (;<<A H H.H H.H H..H25H2J..J25J2c| |D]}t||dS#t$rtd|dYdSwxYw)N)filezcouldn't print to z because of encoding)rUnicodeEncodeError)rzrfpr`s rJrzPytester._dump_linessy A % %d$$$$$ % %! A A A ?r??? @ @ @ @ @ @ As ;;.ctjdfS)Nz-mpytest)r executablers rJ_getpytestargszPytester._getpytestargss~z))rLscriptcB|tj|S)z8Run a python script using sys.executable as interpreter.rnrr)rzrs rJ runpythonzPytester.runpythonsxx///rLrcD|tjd|S)zRun ``python -c "command"``.z-cr)rzrs rJ runpython_czPytester.runpython_csxxg666rL)rcd}t|jdd}d|zf|z}d|jD}|r d|df|z}||z}|j|d |iS) aRun pytest as a subprocess with given arguments. Any plugins added to the :py:attr:`plugins` list will be added using the ``-p`` command line option. Additionally ``--basetemp`` is used to put any temporary files and directories in a numbered directory prefixed with "runpytest-" to not conflict with the normal numbered pytest location for temporary files and directories. :param args: The sequence of arguments to pass to the pytest subprocess. :param timeout: The period in seconds after which to timeout and raise :py:class:`Pytester.TimeoutExpired`. :returns: The result. Tz runpytest-)rootprefixmoderac<g|]}t|t|Sr)rrors rJrz1Pytester.runpytest_subprocess..s'AAAjC.@.@A1AAArLrZrr)r1rrrrn)rzrrrrrs rJr]zPytester.runpytest_subprocesss&! 49\ N N N!#%,AAdlAAA  -'!*%,D""$$t+tx/w///rL$@stringexpect_timeoutz pexpect.spawnc|jdz }|ddtt|}|d|d|}|||S)zRun pytest using pexpect. This makes sure to use the right pytest and sets up the temporary directory locations. The pexpect child is returned. z temp-pexpectr)r z --basetemp=)r)rrrmaprorspawn)rzrrrbinvokecmds rJ spawn_pytestzPytester.spawn_pytests|9~-E"""#c4#6#6#8#899::88X8888zz#nz===rLrctdd}ttdr$dtjvrt dt|dst d|jdd }|j ||| }|j |j |S) zMRun a command using pexpect. The pexpect child is returned. pexpectz3.0r64zpypy-64 bit not supportedrzpexpect.spawn not availablez spawn.outwb)logfiler) r-rrrmachiner.rrrrrrr)rzrrrrchilds rJrzPytester.spawns y%00 3+ , , .9I9K9K1K1K , - - -w(( 0 . / / /)$$[1166t<< c7NKKK ""7=111 rLr7)rr)ri)r)r)Trrrr__test__rr__annotations__rOrr'r4r)rvrpropertyrrrorrrGrr#rrr|rrrrrrrrrrrrrrr rrrr rr*r+rr r rr*r.rr3r,rRrZrDr\rfrr%rlrnrwrErrr8rrr rrtrnrrrrr]rrrrLrJrBrBs H!K!!!         +$+$+$+$*+$! +$  +$ +$+$+$+$ZdX+#++++ % % % % <-? < < < <0C      c5j)* CH~        D1C11s1t1111@030400001c1d1111++++++ 8888883T3333(4d4444*@D55U3(:#:;<5 5555 %%7 78 T     E#'9"9: t    ++#+$++++Z#(.@)@#A y$ *#112 y$ ,%i*@!Ad4j" c c     (s (\ ( ( ( ( d4j,.F(G    !& EEES,,-E E  EEEEN*3 223*?B* ****X M3 223 M?B M  M M M M U3(:#:;<  eC++, -    s,>'>!?F0 E#/A*A$B v    GR  C!334 @C     0'uS*<%<='$t*'''' *  * * *c--. *  * * * *D'* %i( )*&0_%/_8C $$%%7 789$c6k"$c6k" $ Z345 $$$$R$(8C T=T=T=//0T=%T=Z345 T=  T=T=T=T=lAAA*c3h****0 20y000073797777 QU0003 2230>Fuo0 0000:48>>>+0> >>>> erLc2eZdZddZdeeddfdZdS)r9r:Nc,t|_dSr)rstringiors rJrzLineComp.__init__ s  DDrLrcd}|j}|jd|jd|d}t ||dS)zAssert that ``lines2`` are contained (linearly) in :attr:`stringio`'s value. Lines are matched using :func:`LineMatcher.fnmatch_lines `. TrrjN)rrPtruncateseekrwr< fnmatch_lines)rzrrvalrs rJassert_contains_lineszLineComp.assert_contains_linessz !m$$&& q!!! 14F))&11111rLr7)rrrrrrorrrLrJr9r9 sREEEE 2HSM 2d 2 2 2 2 2 2rLc eZdZdZdeeddfdZdefdZdeee ee fde efdZ de eddfd Z de eddfd Z de ed eeegefddfd Zd ede efdZddZedefdZddde ededdfdZddde ededdfdZddde ed eeegefdededdf dZdeddfdZdeddfdZded eeegefdeddfdZdeddfdZdefdZdS) r<zFlexible matching of text. This is a convenience class to test large texts like the output of commands. The constructor takes a list of lines without their trailing newlines, i.e. ``text.splitlines()``. rr:Nc"||_g|_dSr)r _log_output)rzrs rJrzLineMatcher.__init__(s &(rLc6d|jS)zReturn the entire original text. .. versionadded:: 6.2 You can use :meth:`str` in older versions. rj)rrrs rJ__str__zLineMatcher.__str__,s yy$$$rLrct|trt|}t|tr|j}|Sr)rrorrr)rzrs rJ _getlineszLineMatcher._getlines4sF fc " " $F^^F ff % % *\\^^)F rLc@d}||tdS)zTCheck lines exist in the output in any order (using :func:`python:fnmatch.fnmatch`).TN)_match_lines_randomrrzrrs rJfnmatch_lines_randomz LineMatcher.fnmatch_lines_random;s$    11111rLc8d}||ddS)zMCheck lines exist in the output in any order (using :func:`python:re.match`).TcFttj||Srrvrematchrpats rJz3LineMatcher.re_match_lines_random..Cs4d@S@S;T;TrLN)rrs rJre_match_lines_randomz!LineMatcher.re_match_lines_random@s(    )T)TUUUUUrL match_funccd}||}|D]r}|jD]9}||ks |||r%|dt|n0:d|z}||||sdS)NTz matched: line %r not found in output)rr_logr_fail)rzrrrr`rmsgs rJrzLineMatcher._match_lines_randomEs!''  DZ  199 1d 3 39IIk4::666E4d: # 3  rLfnlinect|jD]/\}}||kst||r|j|dzdcS0td|z)zsReturn all lines following the given line in the text. The given line can contain glob wildcards. rlNr)rrrr)rzrrr`s rJget_lines_afterzLineMatcher.get_lines_afterTsl !,, + +GAt~~v!6!6~z!a%''****6?@@@rLct|jdd|DdS)Nrc34K|]}t|VdSrrrs rJrz#LineMatcher._log.._s((>(>AQ(>(>(>(>(>(>rL)rryr)rzrs rJrzLineMatcher._log^s: (>(>(>(>(> > >?????rLc6d|jS)Nrj)rrrs rJ _log_textzLineMatcher._log_textasyy)***rLF consecutivercFd}||td|dS)aCheck lines exist in the output (using :func:`python:fnmatch.fnmatch`). The argument is a list of lines which have to match and can use glob wildcards. If they do not match a pytest.fail() is called. The matches and non-matches are also shown as part of the error message. :param lines2: String patterns to match. :param consecutive: Match lines consecutively? TrrN) _match_linesrrzrrrs rJrzLineMatcher.fnmatch_lineses-! &'9+NNNNNrLc>d}||dd|dS)aCheck lines exist in the output (using :func:`python:re.match`). The argument is a list of lines which have to match using ``re.match``. If they do not match a pytest.fail() is called. The matches and non-matches are also shown as part of the error message. :param lines2: string patterns to match. :param consecutive: match lines consecutively? TcFttj||Srrrs rJrz,LineMatcher.re_match_lines..sd28C#6#677rLre.matchrN)rrs rJre_match_lineszLineMatcher.re_match_linests@!   7 7 #      rLmatch_nicknamect|tjjs$t dt |j||}|jdd}g}d}t|dz}d} |D]} d} |r| d} | | kr'| dt| d} n|| | rb| d|zt| | d d | t| d} n&|ri| rgd | } | | | d d | t| || | s:| d d | t| d} | d d| t| || |d| } | | || g|_dS)aqUnderlying implementation of ``fnmatch_lines`` and ``re_match_lines``. :param Sequence[str] lines2: List of string patterns to match. The actual format depends on ``match_func``. :param match_func: A callable ``match_func(line, pattern)`` where line is the captured line from stdout/stderr and pattern is the matching pattern. :param str match_nickname: The nickname for the match function that will be logged to stdout when a match occurs. :param consecutive: Match lines consecutively? zinvalid type for lines2: NTrlFrz exact match:z%s: {:>{width}}with:widthzno consecutive match: nomatch:and:zremains unmatched: )r collectionsabcr TypeErrorrCrrrrrrrrrryr)rzrrrrr extralinesrwnickstartedr`nomatchprintednextliners rJrzLineMatcher._match_liness.&+/":;; QOV 8MOOPP P''AAA  N##a'! ! D"N !::a==8##IInd4jj999"GZ$//YIIen4d4jjAAAII%,,WE,BBDNN#G"(w(?t?? # )000FFX 3). )0050II4PT::*.IIm2262GGhXXX!!(+++7 :5D44 # 3rLrcBd}||tddS)zEnsure captured lines do not match the given pattern, using ``fnmatch.fnmatch``. :param str pat: The pattern to match lines. TrN)_no_match_linerrzrrs rJno_fnmatch_linezLineMatcher.no_fnmatch_lines( ! C)44444rLc:d}||dddS)zEnsure captured lines do not match the given pattern, using ``re.match``. :param str pat: The regular expression to match lines. TcFttj||Srrrs rJrz.LineMatcher.no_re_match_line..s4d(;(;#<#<rLrN)rr s rJno_re_match_linezLineMatcher.no_re_match_lines7 !  < XrLc t|S)z Return the entire original text.rrs rJrozLineMatcher.strs4yyrLr7)rrrrr rorrrrrrrrrrvrrrrrrrrr r rrrrLrJr<r<sM)d3i)D))))%%%%%c8C=&&@ Ahsm28C=2T2222 VHSMVdVVVV  sm  193*d:J1K       AcAhsmAAAA@@@@+3+++X+=B O O Osm O59 O  O O O O =B   sm 59     6" AAA Ac3Z-.A A  A AAAAF53545555 C D    $,c3Z-=$>PS . SrL)r:r9)srcollections.abcrrrr?rtrprrrrErrPriorpathlibrtypingrrrr r r r r rrrrrrrweakrefr iniconfigrrrr _pytest._coder_pytest.capturer_pytest.compatrrrrNrrr r!r"r#_pytest.config.argparsingr$_pytest.deprecatedr%_pytest.fixturesr&r' _pytest.mainr(_pytest.monkeypatchr) _pytest.nodesr*r+_pytest.outcomesr,r-r._pytest.pathlibr/r0r1_pytest.reportsr2r3_pytest.tmpdirr4_pytest.warning_typesr5typing_extensionsr6r7rpytest_pluginsrxrKrWrQrrorrrr;r?rDrKrPcompilerirkrRrwrGrFrBr9r<rrLrJr*sQ     %%%%%%$$$$$$ ------ !!!!!!%%%%%%((((((!!!!!!############......,,,,,,------$$$$$$++++++ ++++++######!!!!!!))))))!!!!!!''''''$$$$$$------))))))&&&&&&******//////''''''))))))NNN(( V2 V     ?7?7?7?7?7?7?7?7J ^  .Xc].tCy.... 8VVVVVVVVr    mD4G  L  L/> LMX L L L L  L  y!12  !)FD$$67!!! !"rz-00bj(( g g g g g g g g T ) ) ) ) ) ) ) )55555555u u u u u u u u p22222222$__________rL