Meta tags:
description= Python enthusiast, core developer, psutil author;
Headings (most frequently used words):
python, to, free, threaded, pytest, the, psutil, for, discussion, what, is, it, of, polling, memory, with, and, psleak, wheels, extension, new, state, links, heap, means, time, giampaolo, rodola, enthusiast, core, developer, author, from, today, ending, 15, years, subprocess, detecting, leaks, in, extensions, now, available, speeding, up, startup, brave, chrome, reorder, tabs, problem, busy, event, driven, waiting, linux, macos, bsd, windows, graceful, fallbacks, measurement, sleeping, cpython, contribution, why, native, introspection, matters, heap_info, direct, allocator, statistics, heap_trim, returning, unused, real, world, use, finding, leak, tool, under, hood, references, users, library, authors, how, install, preface, migration, invocation, slow, where, being, spent, disable, plugin, auto, loading, handling, xdist, optimizing, test, collection, putting, all, together, other, which, may, be, useful, social, feed,
Text of the page (most frequently used words):
the (112), #psutil (63), and (49), for (42), python (41), #pytest (37), this (32), time (31), python3 (30), process (26), that (24), with (22), heap (21), select (20), packages (20), you (19), can (18), run (18), free (18), pid (18), tab (17), from (17), rss (17), test (16), tests (16), calls (16), memory (16), when (15), xdist (15), local (15), lib (15), site (15), timeout (15), import (14), see (13), threaded (13), poll (13), which (12), wheels (12), whl (12), uss (12), call (12), not (11), real (11), without (11), windows (11), after (10), them (10), only (10), now (10), avg (10), new (9), are (9), via (9), _pytest (9), allocator (9), heap_used (9), extensions (8), but (8), return (8), 0m0 (8), malloc (8), mmap_used (8), kqueue (8), wait (8), sleep (8), context (8), chrome (7), these (7), same (7), extension (7), how (7), all (7), def (7), still (7), back (7), library (7), cpython (7), leak (7), psleak (7), leaks (7), approach (7), subprocess (7), file (7), tabs (6), index (6), files (6), one (6), out (6), also (6), reduce (6), mark (6), pytest_disable_plugin_autoload (6), they (6), what (6), years (6), wheel (6), cp313 (6), cp313t (6), cp314 (6), cp314t (6), means (6), has (6), cpu (6), was (6), before (6), module (6), busy (6), brave (5), changeinfo (5), url (5), while (5), have (5), using (5), because (5), each (5), simple (5), tags (5), small (5), runs (5), running (5), where (5), xdist_group (5), obj (5), uses (5), used (5), system (5), unittest (5), most (5), build (5), install (5), directly (5), multiple (5), code (5), many (5), proposal (5), bsd (5), macos (5), allocations (5), native (5), heap_info (5), platform (5), pidfd_open (5), switches (5), events (5), background (4), enable (4), move_tab (4), com (4), function (4), use (4), here (4), 2025 (4), startup (4), tool (4), warning (4), parallel (4), instafail (4), subtests (4), plugins (4), plugin (4), there (4), compiled (4), source (4), single (4), users (4), state (4), core (4), linux (4), metrics (4), vms (4), number (4), heap_trim (4), standard (4), added (4), parameter (4), first (4), stat (4), waiting (4), kernel (4), loop (4), syscall (4), polling (4), until (4), epoll (4), descriptor (4), interval (4), click (3), changes (3), your (3), teams (3), includes (3), slack (3), status (3), position (3), name (3), always (3), work (3), turns (3), alt (3), https (3), seconds (3), improvement (3), repeatedly (3), command (3), something (3), another (3), overhead (3), patch (3), just (3), true (3), since (3), disabled (3), following (3), register (3), disable (3), get (3), much (3), than (3), 427s (3), actually (3), test_misc (3), testmisc (3), test_version (3), passed (3), let (3), again (3), anyio (3), pytest_cov (3), looponfail (3), even (3), about (3), itself (3), two (3), were (3), reddit (3), discussion (3), pip (3), will (3), authors (3), essential (3), currently (3), package (3), especially (3), such (3), often (3), take (3), several (3), effort (3), effectively (3), 128 (3), provide (3), made (3), available (3), testing (3), glibc (3), mmap (3), monitoring (3), fail (3), above (3), exactly (3), noise (3), its (3), way (3), unix (3), reference (3), example (3), level (3), modules (3), etc (3), show (3), into (3), traditional (3), similar (3), bpo (3), both (3), zero (3), usr (3), bin (3), event (3), driven (3), more (3), descriptors (3), timeouterror (3), raise (3), exits (3), systems (3), poller (3), check (3), linkedin (2), github (2), console (2), folder (2), top (2), right (2), developer (2), move_new_tabs (2), microsoft (2), complete (2), loading (2), move (2), version (2), almost (2), gmail (2), find (2), place (2), frequently (2), manually (2), started (2), needs (2), create (2), should (2), apr (2), projects (2), org (2), html (2), links (2), down (2), makes (2), during (2), development (2), collection (2), test_ (2), adding (2), auto (2), disappears (2), serially (2), fake_xdist_group (2), wrapper (2), inner (2), type (2), kwargs (2), args (2), functools (2), method (2), decorated (2), class (2), decorator (2), pytest_parallel (2), those (2), longer (2), implemented (2), serial (2), test_testutils (2), 367 (2), custom (2), 369s (2), went (2), 320s (2), better (2), original (2), 285s (2), later (2), 05s (2), pytest_instafail (2), pytest_subtests (2), collect (2), trace (2), config (2), setupplan (2), stepwise (2), warnings (2), logging (2), reports (2), python_path (2), unraisableexception (2), threadexception (2), faulthandler (2), significant (2), fast (2), why (2), second (2), under (2), measure (2), very (2), execution (2), slow (2), aspects (2), year (2), plain (2), performance (2), pre (2), binary (2), universal (2), would (2), allowing (2), versions (2), pep (2), macosx_11_0_arm64 (2), manylinux2010_x86_64 (2), manylinux_2_12_x86_64 (2), manylinux_2_28_x86_64 (2), manylinux2014_aarch64 (2), manylinux_2_17_aarch64 (2), manylinux_2_28_aarch64 (2), win_amd64 (2), win_arm64 (2), must (2), specifically (2), author (2), provides (2), like (2), largely (2), require (2), installing (2), tools (2), 360 (2), pypi (2), builds (2), gil (2), shows (2), ready (2), across (2), community (2), internal (2), make (2), thanks (2), medium (2), hacker (2), news (2), implementation (2), stats (2), statistics (2), heaps (2), usage (2), virtualalloc (2), heapalloc (2), blocks (2), don (2), detect (2), py_decref (2), suite (2), apis (2), increasing (2), 200 (2), 1940 (2), 819200 (2), 1945 (2), 1146880 (2), 1946 (2), 1000 (2), exception (2), self (2), memoryleaktestcase (2), consistently (2), times (2), helps (2), delta (2), print (2), snapshot (2), baseline (2), won (2), caching (2), request (2), underlying (2), any (2), unused (2), typically (2), returning (2), heap_count (2), heapcreate (2), large (2), field (2), total (2), bytes (2), allocated (2), object (2), counts (2), introspection (2), track (2), usually (2), straightforward (2), sits (2), featured (2), extend (2), asyncio (2), pids (2), ago (2), took (2), around (2), commit (2), popen (2), thing (2), inspired (2), landed (2), shutil (2), disk_usage (2), getpid (2), pollin (2), comm (2), dev (2), null (2), sleeps (2), interesting (2), sleeping (2), grep (2), voluntary (2), involuntary (2), copy (2), efficient (2), regular (2), 1024 (2), rather (2), does (2), kev (2), block (2), occurs (2), expires (2), chose (2), over (2), bit (2), wakes (2), terminates (2), pidfd (2), referencing (2), posix (2), blog (2), pid_done (2), wnohang (2), waitpid (2), end (2), monotonic (2), giampaolo (2), rodola (2), atom, feed, social, page, editing, refresh, icon, apply, observe, debug, messages, printed, service, worker, load, unpacked, mode, tabid, addlistener, onupdated, app, mail, google, moving, log, service_worker, permissions, set, description, repositioner, manifest_version, manifest, json, put, browsing, keep, three, open, convenient, quickly, switch, keyboard, shortcuts, remains, closing, evening, reopening, next, morning, reposition, automate, looking, couldn, fully, met, decided, spend, little, writing, own, incredibly, easy, dotfiles, reorder, gentoo, guide, zupo, awesome, speedup, other, may, useful, optimizations, managed, bringing, insignificant, full, noticeable, difference, faster, individual, line, final, result, visible, 2538, putting, together, dropped, 20s, 17s, 03s, shaved, off, python_files, testpaths, ini_options, default, searches, entire, directory, unnecessary, tell, located, consider, pyproject, toml, optimizing, dist, loadgroup, monkey, else, isinstance, wraps, mimics, _kwargs, _args, environ, pytest_xdist_worker, appears, methods, intended, however, exists, address, solution, __init__, svn, pytestunknownmarkwarning, unknown, typo, marks, avoid, details, docs, stable, handling, pity, pay, price, quite, slowdown, bad, need, selectively, deal, environment, variable, disappeared, active, pytest_plugin, some, research, discovered, automatically, loads, installed, aren, list, output, cut, 151s, 065s, 056s, portion, comes, being, spent, roughly, twice, ran, 000s, 204s, half, excessive, comparison, negligible, invocation, want, focus, frustrating, last, adopting, advantages, cared, statements, parallelism, inherit, fixture, rationale, 2456, conftest, testcase, assert, 2446, preface, migration, speeding, ensures, triggering, multiplies, jobs, slows, matrix, greatly, support, platforms, hopefully, simplify, competing, proposals, aim, standardize, naming, metadata, allow, producing, covers, drastically, distribution, complexity, fair, say, truly, succeed, 809, 803, yml, macosx_10_13_x86_64, macosx_10_15_x86_64, built, separate, distributing, already, lot, exist, having, important, written, complex, requirements, compiler, visual, studio, gigabytes, setup, providing, spares, hassle, installation, far, simpler, basically, done, according, hugo, van, kemenade, adoption, among, downloaded, limited, meaning, progress, been, popular, offer, tracker, refers, bytecodes, threads, particularly, beneficial, bound, applications, enables, utilization, multi, processors, global, interpreter, lock, release, milestone, achieved, through, refactorings, required, possible, contributed, him, bearing, reviews, lysandros, nikolaou, 2565, oct, earlier, 1275, 2692, framework, references, jemalloc, arena, interfaces, zone, enumerates, aggregates, report, backed, hblkhd, uordblks, mallinfo2, interested, seeing, did, terms, hood, worth, noting, inspecting, missing, unnoticed, affect, confirmed, commenting, therefore, reliably, py_clear, part, tested, making, facto, regression, test_memleaks, memoryleakerror, kept, 388160, 356352, 327680, 584848, 614400, 491520, 300, 1949, 778320, 782336, 400, 970512, 1032192, 500, 1941, 1169024, 1171456, 600, 1948, 1357360, 1413120, 1310720, 700, 1939, 1552336, 1634304, 1638400, 800, 1752032, 1781760, 1802240, 900, 1945056, 2031616, 2129920, 2140624, 2179072, 2293760, 1100, descriptive, some_c_function, execute, test_fun, testleaks, minimal, looks, strategy, described, called, target, trims, tracks, differences, retries, grows, flagged, false, positives, repeat, retry, distinguish, random, transient, values, increase, found, my_cext_function, range, compare, hundreds, workflow, world, finding, practice, modern, allocators, rarely, comply, general, purpose, reduction, meaningfully, shrink, programs, primary, value, detection, calling, taking, measurements, giving, cleaner, come, fragmentation, cross, holding, heapdestroy, virtualfree, heapfree, munmap, affected, allocation, contributes, pheap, 5177792, private, created, exposes, direct, functions, query, low, due, objects, happen, forget, tracemalloc, sys, getrefcount, rely, numpy, pandas, pil, lxml, psycopg, pytorch, house, implements, components, mishandle, doesn, matters, introduces, designed, catch, kinds, give, window, letting, layer, allocates, flat, climbs, diagnose, look, follow, graphs, inside, story, reveal, corresponding, know, pymalloc, api, dec, detecting, optimization, selectors, 144211, asynchronous, integration, 2703, wait_procs, 2712, topics, related, probably, inspiration, contributing, circle, funny, 2011, ideas, 2010, 10784, setpriority, getpriority, nice, proud, history, feature, developed, upstream, third, landing, extra, step, submitted, matching, pull, 144047, 2706, contribution, 10_000, 491748, 491573, shown, below, foreground, note, puts, exact, perspective, interruptible, scheduled, consumes, quietly, space, instead, spinning, userspace, woken, notifies, resulting, few, 258, switching, pass, timeoutexpired, except, try, experiment, program, waits, terminating, measurement, path, fallback, spirit, sped, 2018, attempted, fails, network, filesystems, fall, write, read, sendfile, copyfile, 33671, different, reasons, explicitly, blocked, sysadmin, seccomp, cases, silently, falls, raising, eperm, eacces, emfile, graceful, fallbacks, had, start, nothing, front, waitforsingleobject, control, kq_note_exit, fflags, kq_ev_oneshot, kq_ev_add, flags, kq_filter_proc, filter, kevent, wait_kqueue, derived, including, conceptually, powerful, handle, once, creating, additional, historical, limit, caps, per, reminded, 1685000, fd_setsize, looping, alive, wait_pidfd, 2019, introduced, returns, conjunction, least, mechanism, notified, becomes, recently, believed, could, sockets, pipes, scalability, processes, simultaneously, magnifies, latency, gap, between, wake, ups, exponential, backoff, starting, 1ms, capping, 40ms, constantly, wasting, cycles, draining, batteries, problem, post, finally, addressed, long, standing, inefficiency, excitingly, min, 0001, wait_busy, logic, whether, exited, non, blocking, briefly, less, fun, management, terminate, relied, technique, jan, 2026, today, ending, donate, archives, enthusiast,
Text of the page (random words):
parameter the circle is complete links topics related to this 2712 proposal to extend this to multiple pids psutil wait_procs 2703 proposal for asynchronous process wait integration with asyncio cpython 144211 proposal to extend the selectors module to enable asyncio optimization on bsd macos via kqueue discussion reddit hacker news medium linkedin detecting memory leaks in c extensions with psutil and psleak featured 23 dec 2025 tags psutil python memory c new api memory leaks in python are usually straightforward to diagnose just look at rss track python object counts follow reference graphs etc but leaks inside c extension modules are another story traditional memory metrics such as rss and vms fail to reveal them because python s memory allocator pymalloc sits above the platform s native heap if something in an extension calls malloc without a corresponding free that memory often won t show up in rss vms you have a leak and you don t know psutil 7 2 0 introduces two new apis for c heap introspection designed specifically to catch these kinds of native leaks they give you a window directly into the underlying platform allocator e g glibc s malloc letting you track how much memory the c layer actually allocates if your rss is flat but your c heap usage climbs you now have a way to see it why native heap introspection matters many python projects rely on c extensions psutil numpy pandas pil lxml psycopg pytorch custom in house modules etc and even cpython itself which implements many of its standard library modules in c if any of these components mishandle memory at the c level you get a leak that doesn t show up in python reference counts sys getrefcount tracemalloc module python s gc stats rss vms or uss due to allocator caching especially for small objects this can happen for example when you forget to py_decref a python object psutil s new functions let you query the allocator e g glibc directly returning low level metrics from the platform s native heap heap_info direct allocator statistics psutil heap_info exposes the following metrics heap_used total number of bytes currently allocated via malloc small allocations mmap_used total number of bytes currently allocated via mmap or via large malloc allocations heap_count windows only number of private heaps created via heapcreate example import psutil psutil heap_info pheap heap_used 5177792 mmap_used 819200 reference for what contributes to each field platform allocation type field affected unix windows small malloc 128 kb without free heap_used unix windows large malloc 128 kb without free or mmap without munmap unix mmap_used windows heapalloc without heapfree heap_used windows virtualalloc without virtualfree mmap_used windows heapcreate without heapdestroy heap_count heap_trim returning unused heap memory psutil heap_trim provides a cross platform way to request that the underlying allocator free any unused memory it s holding in the heap typically small malloc allocations in practice modern allocators rarely comply so this is not a general purpose memory reduction tool and won t meaningfully shrink rss in real programs its primary value is in leak detection tools calling psutil heap_trim before taking measurements helps reduce allocator noise giving you a cleaner baseline so that changes in heap_used come from the code you re testing not from internal allocator caching or fragmentation real world use finding a c extension leak the workflow is simple take a baseline snapshot of the heap call the c extension hundreds of times take another snapshot compare import psutil psutil heap_trim reduce noise before psutil heap_info for _ in range 200 my_cext_function after psutil heap_info print delta heap_used after heap_used before heap_used print delta mmap_used after mmap_used before mmap_used if heap_used or mmap_used values increase consistently you ve found a native leak to reduce false positives repeat the test multiple times increasing the number of calls on each retry this approach helps distinguish real leaks from random noise or transient allocations a new tool psleak the strategy described above is exactly what i implemented in a new pypi package which i called psleak it runs the target function repeatedly trims the allocator before each run and tracks differences across retries memory that grows consistently after several runs is flagged as a leak a minimal test suite looks like this from psleak import memoryleaktestcase class testleaks memoryleaktestcase def test_fun self self execute some_c_function if the function leaks memory the test will fail with a descriptive exception psleak memoryleakerror memory kept increasing after 10 runs run 1 heap 388160 uss 356352 rss 327680 calls 200 avg call 1940 run 2 heap 584848 uss 614400 rss 491520 calls 300 avg call 1949 run 3 heap 778320 uss 782336 rss 819200 calls 400 avg call 1945 run 4 heap 970512 uss 1032192 rss 1146880 calls 500 avg call 1941 run 5 heap 1169024 uss 1171456 rss 1146880 calls 600 avg call 1948 run 6 heap 1357360 uss 1413120 rss 1310720 calls 700 avg call 1939 run 7 heap 1552336 uss 1634304 rss 1638400 calls 800 avg call 1940 run 8 heap 1752032 uss 1781760 rss 1802240 calls 900 avg call 1946 run 9 heap 1945056 uss 2031616 rss 2129920 calls 1000 avg call 1945 run 10 heap 2140624 uss 2179072 rss 2293760 calls 1100 avg call 1946 psleak is now part of the psutil test suite all psutil apis are tested see test_memleaks py making it a de facto regression testing tool it s worth noting that without inspecting heap metrics missing calls in the c code such as py_clear and py_decref often go unnoticed because they don t affect rss vms and uss i confirmed this by commenting them out monitoring the heap is therefore essential to reliably detect memory leaks in python c extensions under the hood for those interested in seeing how i did this in terms of code linux uses glibc s mallinfo2 to report uordblks heap allocations and hblkhd mmap backed blocks windows enumerates heaps and aggregates heapalloc virtualalloc usage macos uses malloc zone statistics bsd uses jemalloc s arena and stats interfaces references psleak the new memory leak testing framework pr 2692 the implementation 1275 the original proposal from 8 years earlier discussion reddit hacker news medium wheels for free threaded python now available 25 oct 2025 tags psutil python wheels community python core with the release of psutil 7 1 2 wheels for free threaded python are now available this milestone was achieved largely through a community effort as several internal refactorings to the c code were required to make it possible see 2565 many of these changes were contributed by lysandros nikolaou thanks to him for the effort and for bearing with me in code reviews what is free threaded python free threaded python available since python 3 13 refers to python builds that are compiled with the gil global interpreter lock disabled allowing true parallel execution of python bytecodes across multiple threads this is particularly beneficial for cpu bound applications as it enables better utilization of multi core processors the state of free threaded wheels according to hugo van kemenade s free threaded wheels tracker the adoption of free threaded wheels among the top 360 most downloaded pypi packages with c extensions is still limited only 128 out of these 360 packages provide wheels compiled for free threaded python meaning they can run on python builds with the gil disabled this shows that while progress has been made most popular packages with c extensions still do not offer ready made wheels for free threaded python what it means for users when a library author provides a wheel users can install a pre compiled binary package without having to build it from source this is especially important for packages with c extensions like psutil which is largely written in c such packages often have complex build requirements and require installing a c compiler on windows that means installing visual studio or the build tools which can take several gigabytes and a significant setup effort providing wheels spares users from this hassle makes installation far simpler and is effectively essential for the users of that package you basically pip install psutil and you re done what it means for library authors currently universal wheels for free threaded python do not exist each wheel must be built specifically for a python version right now authors must create separate wheels for python 3 13 and 3 14 which means distributing a lot of files already psutil 7 1 2 cp313 cp313t macosx_10_13_x86_64 whl psutil 7 1 2 cp313 cp313t macosx_11_0_arm64 whl psutil 7 1 2 cp313 cp313t manylinux2010_x86_64 manylinux_2_12_x86_64 manylinux_2_28_x86_64 whl psutil 7 1 2 cp313 cp313t manylinux2014_aarch64 manylinux_2_17_aarch64 manylinux_2_28_aarch64 whl psutil 7 1 2 cp313 cp313t win_amd64 whl psutil 7 1 2 cp313 cp313t win_arm64 whl psutil 7 1 2 cp314 cp314t macosx_10_15_x86_64 whl psutil 7 1 2 cp314 cp314t macosx_11_0_arm64 whl psutil 7 1 2 cp314 cp314t manylinux2010_x86_64 manylinux_2_12_x86_64 manylinux_2_28_x86_64 whl psutil 7 1 2 cp314 cp314t manylinux2014_aarch64 manylinux_2_17_aarch64 manylinux_2_28_aarch64 whl psutil 7 1 2 cp314 cp314t win_amd64 whl psutil 7 1 2 cp314 cp314t win_arm64 whl this also multiplies ci jobs and slows down the test matrix see build yml a true universal wheel would greatly reduce this overhead allowing a single wheel to support multiple python versions and platforms hopefully python 3 15 will simplify this process two competing proposals pep 803 and pep 809 aim to standardize wheel naming and metadata to allow producing a single wheel that covers multiple python versions that would drastically reduce distribution complexity for library authors and it s fair to say it s essential for free threaded cpython to truly succeed how to install free threaded psutil you can now install psutil for free threaded python directly via pip pip install psutil only binary all this ensures you get the pre compiled wheels without triggering a source build discussion reddit speeding up pytest startup 04 apr 2025 tags psutil python tests performance preface the migration to pytest last year after 17 years of unittest i started adopting pytest in psutil see 2446 the two advantages i cared about most were plain assert statements and pytest xdist s free parallelism tests still inherit from unittest testcase and there s no conftest py or fixture use rationale in pr 2456 what i want to focus on here is one of pytest s most frustrating aspects slow startup pytest invocation is slow to measure pytest s startup time let s run a very simple test where execution time itself is negligible time python3 m pytest psutil tests test_misc py testmisc test_version 1 passed in 0 05s real 0m0 427s almost half a second which is excessive for something i run repeatedly during development for comparison the same test under unittest time python3 m unittest psutil tests test_misc testmisc test_version ran 1 test in 0 000s real 0m0 204s roughly twice as fast why where is time being spent a significant portion of pytest s overhead comes from import time and there s not much one can do about it time python3 c import pytest real 0m0 151s time python3 c import unittest real 0m0 065s time python3 c import psutil real 0m0 056s disable plugin auto loading after some research i discovered that pytest automatically loads all plugins installed on the system even if they aren t used here s how to list them output is cut pytest trace config collect only active plugins setupplan local lib python3 12 site packages _pytest setupplan py stepwise local lib python3 12 site packages _pytest stepwise py warnings local lib python3 12 site packages _pytest warnings py logging local lib python3 12 site packages _pytest logging py reports local lib python3 12 site packages _pytest reports py python_path local lib python3 12 site packages _pytest python_path py unraisableexception local lib python3 12 site packages _pytest unraisableexception py threadexception local lib python3 12 site packages _pytest threadexception py faulthandler local lib python3 12 site packages _pytest faulthandler py instafail local lib python3 12 site packages pytest_instafail py anyio local lib python3 12 site packages anyio pytest_plugin py pytest_cov local lib python3 12 site packages pytest_cov plugin py subtests local lib python3 12 site packages pytest_subtests plugin py xdist local lib python3 12 site packages xdist plugin py xdist looponfail local lib python3 12 site packages xdist looponfail py it turns out pytest_disable_plugin_autoload environment variable can be used to disable them by running pytest_disable_plugin_autoload 1 pytest trace config collect only again i can see that the following plugins disappeared anyio pytest_cov pytest_instafail pytest_subtests xdist xdist looponfail now let s run the test again with pytest_disable_plugin_autoload time pytest_disable_plugin_autoload 1 python3 m pytest psutil tests test_misc py testmisc test_version 1 passed in 0 05s real 0m0 285s we went from 0 427s to 0 285s a 40 improvement not bad we now need to selectively enable only the plugins we actually use via p psutil uses pytest instafail and pytest subtests we ll deal with pytest xdist later time pytest_disable_plugin_autoload 1 python3 m pytest p instafail p subtests real 0m0 320s time went back up to 0 320s quite a slowdown but still better than the original 0 427s adding pytest xdist time pytest_disable_plugin_autoload 1 python3 m pytest p instafail p subtests p xdist real 0m0 369s 0 369s not much but still a pity to pay the price when not running tests in parallel handling pytest xdist if we disable pytest xdist psutil tests still run but we get a warning psutil tests test_testutils py 367 svn psutil psutil tests test_testutils py 367 pytestunknownmarkwarning unknown pytest mark xdist_group is this a typo you can register custom marks to avoid this warning for details see https docs pytest org en stable how to mark html pytest mark xdist_group name serial this warning appears for methods that are intended to run serially those decorated with pytest mark xdist_group name serial however since pytest xdist is now disabled the decorator no longer exists to address this i implemented the following solution in psutil tests __init__ py import pytest functools pytest_parallel pytest_xdist_worker in os environ true if running parallel tests if not pytest_parallel def fake_xdist_group _args _kwargs mimics pytest mark xdist_group decorator no op it just calls the test method or return the decorated class def wrapper obj functools wraps obj def inner args kwargs return obj args kwargs return obj if isinstance obj type else inner return wrapper pytest mark xdist_group fake_xdist_group monkey patch with this in place the warning disappears when running tests serially to run tests in parallel we ll manually enable xdist python3 m pytest p xdist n a...
|