certbot/certbot
Adrien Ferrand ca25d1b66a Call atexit handlers before test tearDown to remove errors on Windows (#6667)
When certbot is executing, several resources are opened. It is typically file handles and locks on them. Of course, theses resources need to be cleanup. It is done in Certbot by registering cleanup functions through atexit module, that ensures theses functions will be called when Certbot exit. This allow to not care about resource cleanup everywhere in the code, as it is processed globally.

The problem with atexit is it cleanup functions are called when the Python program exit. If the program is Certbot itself when used, this is Pytest in unit test execution. So during a unit test execution, cleanup is not called after a test and before its tearDown, but when Pytest exit, so way after tests and their respective tearDown.

But many tearDown implies to delete folders where this kind of resources are hold.

This is never a problem on Linux, thanks to its non-blocking file handling. It is usually not a problem on Windows, despite its blocking approach. But if the tearDown requires folder cleanup, exceptions are raised, and currently hidden as warnings. There is currently 504 exceptions of this type in Certbot core tests on Windows.

This PR starts to correct this situation. To do so, some of the functions cleanup normally called through atexit, are explicitly called as part of the tearDown process of relevant test classes, before directory removal is done. Theses situations come all from the certbot.tests.util.TempDirTestCase, so the code is in this specific tearDown process.

As a consequence, exceptions drop from 504 to 64.

Then there are still a significant part of them, that will be handled in later mitigation.

* Call atexit handlers before test tearDown to reduce errors on Windows

* Clear locks dict after global releasing execution

* Remove last tearDown errors.

* Clean out mock on open.

* Remove a test

* Reenable some tests
2019-01-29 19:25:05 -08:00
..
display [Windows] Change default paths for Certbot when run on Windows (#6416) 2018-11-20 14:06:09 -08:00
plugins Update Certbot dependency to Lexicon to 3.x (#6593) 2019-01-10 11:36:15 -08:00
tests Call atexit handlers before test tearDown to remove errors on Windows (#6667) 2019-01-29 19:25:05 -08:00
.gitignore s/letsencrypt/certbot 2016-04-13 16:03:59 -07:00
__init__.py Bump version to 0.31.0 2019-01-02 12:33:31 -08:00
account.py Make Certbot runnable on Windows (#6296) 2018-09-08 07:34:27 -07:00
achallenges.py Use josepy instead of acme.jose. (#5203) 2017-12-11 11:25:09 -08:00
auth_handler.py [Windows|Unix] Avoid to re-execute challenges already validated (#6551) 2019-01-09 12:52:53 -08:00
cert_manager.py Make Certbot runnable on Windows (#6296) 2018-09-08 07:34:27 -07:00
cli.py Update --help for --delete-after-revoke to clarify that the flag deletes the entire lineage 2019-01-15 12:05:00 -08:00
client.py WIP External Account Binding (#6059) 2018-12-03 15:27:35 -08:00
compat.py Fix default directories on Linux (#6560) 2018-12-05 14:52:58 -08:00
configuration.py Reuse ACMEv1 accounts for ACMEv2 (#5902) 2018-06-04 16:04:47 -07:00
constants.py Tag to disable random sleep upon a renew task (#6599) 2018-12-18 16:17:54 -08:00
crypto_util.py no newline in py27 2018-11-05 17:47:38 -08:00
eff.py Changing opt-in ask for emails (#6035) 2018-05-23 20:40:34 -07:00
error_handler.py Prepare certbot module for mypy check untyped defs (#6005) 2018-05-18 06:28:17 -07:00
errors.py PluginStorage to store variables between invocations. (#5468) 2018-04-11 08:54:55 -07:00
hooks.py Prepare certbot module for mypy check untyped defs (#6005) 2018-05-18 06:28:17 -07:00
interfaces.py Do not call IPlugin.prepare() for updaters when running renew (#6167) 2018-07-06 13:19:29 -07:00
lock.py Make Certbot runnable on Windows (#6296) 2018-09-08 07:34:27 -07:00
log.py Make Certbot runnable on Windows (#6296) 2018-09-08 07:34:27 -07:00
main.py Modify delete after revoke question to clarify that the flag deletes the entire lineage 2019-01-15 12:03:49 -08:00
notify.py s/Let's Encrypt/Certbot 2016-04-13 16:13:50 -07:00
ocsp.py warn-->warning 2018-10-31 18:11:43 -07:00
renewal.py Tag to disable random sleep upon a renew task (#6599) 2018-12-18 16:17:54 -08:00
reporter.py Refactoring for better logging (#4444) 2017-03-30 16:17:57 -07:00
reverter.py [Windows] Handle file renaming when the destination path already exists (#6415) 2018-11-06 15:35:09 -08:00
ssl-dhparams.pem Use ffdhe2048 Nginx DH params to fix Weak-DH bug (#4973) 2017-09-01 07:57:30 -07:00
storage.py Remove dead autodeployment code (#6678) 2019-01-20 19:17:03 +01:00
updater.py Do not call IPlugin.prepare() for updaters when running renew (#6167) 2018-07-06 13:19:29 -07:00
util.py Call atexit handlers before test tearDown to remove errors on Windows (#6667) 2019-01-29 19:25:05 -08:00