From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jens Schmidt Newsgroups: gmane.emacs.devel Subject: ERT: How to implement expensive initialization and cleanup? Date: Sun, 4 Jun 2023 22:04:23 +0200 Message-ID: <46df52d2-5f3d-7807-c396-9838a219543e@vodafonemail.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32756"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jun 04 22:05:26 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q5tyf-0008I9-Ti for ged-emacs-devel@m.gmane-mx.org; Sun, 04 Jun 2023 22:05:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q5txu-0000wm-Dr; Sun, 04 Jun 2023 16:04:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q5txs-0000wc-6h for emacs-devel@gnu.org; Sun, 04 Jun 2023 16:04:36 -0400 Original-Received: from mr5.vodafonemail.de ([145.253.228.165]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q5txq-0005Ee-0c for emacs-devel@gnu.org; Sun, 04 Jun 2023 16:04:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vodafonemail.de; s=vfde-mb-mr2-21dec; t=1685909071; bh=LwVsEKq3OnSfR2y7sm0/ZAgJO9lnY79UvqZixQObYeY=; h=Message-ID:Date:User-Agent:Content-Language:From:To:Subject: Content-Type:From; b=m87TUbiqnLmcoR7a1rSzLz3uGrWxu53N951AqTLOtUyxgppMTEeUzbHOhwAeo9Mvg TKAI/Eer6Y+dkVXEr0kzXgOoHSF7x2GCOa7txQuZaweHS3uU0XlOEhgyrshcKyBxpD XlNBLtk7RQqfp37ki7ARJoce7AVKHCCfObblC68c= Original-Received: from smtp.vodafone.de (unknown [10.0.0.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mr5.vodafonemail.de (Postfix) with ESMTPS id 4QZ74H1R2rz1y1D for ; Sun, 4 Jun 2023 20:04:31 +0000 (UTC) Original-Received: from [192.168.178.41] (port-92-194-57-212.dynamic.as20676.net [92.194.57.212]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp.vodafone.de (Postfix) with ESMTPSA id 4QZ74B6pVbzKm4G for ; Sun, 4 Jun 2023 20:04:23 +0000 (UTC) Content-Language: de-DE-frami, en-US X-purgate-type: clean X-purgate: clean X-purgate-size: 1422 X-purgate-ID: 155817::1685909067-93FFE4F8-AFEA5113/0/0 Received-SPF: pass client-ip=145.253.228.165; envelope-from=jschmidt4gnu@vodafonemail.de; helo=mr5.vodafonemail.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:306626 Archived-At: Trying to write my first ERT test. For the tests I need to set up a GnuPG home directory from scratch, including directory creation, key import, and key trust management. Plus I need to clean up that mess after the tests have finished. Takes some 2secs on my system with all that process communication between Emacs and GnuPG. The cleanest solution would be to do that for every test, but that would get expensive if I go for many small tests, which seems to be better in terms of diagnosability. So a one-time setup at the beginning of "all tests" and a one-time cleanup at the end of "all tests" would be what I need, independently of where "all tests" begin and end: It might be really all tests when I do a batch run or just one test when I execute `ert-run-tests-interactively'. I thought about some `ert-setup-hook' and `ert-cleanup-hook' executed e.g. in `ert-run-tests', but I haven't found anything like that. Besides that, this works out only if you run tests from only one "test set" which all share the same setup and cleanup. Lazy initialization would also work for this kind or problem, but how would I trigger "lazy cleanup", then? Just leave (in my case) the temporary GnuPG home directory to be cleaned up by the OS? Or at least clean it up at the end of the test file, which would cover the batch tests, but not single tests? Anything else? Thanks