Currently, the _ActorType.exit() method includes the following conditional check to prevent sys.exit() from being executed during tests:
elif os.getenv('PYTEST_CURRENT_TEST', default=False): # noqa: PLW1508
self.log.debug(f'Not calling sys.exit({exit_code}) because Actor is running in an unit test')
This approach relies on environment variables to modify production code behavior, which is not ideal. Instead, tests should either configure the Actor to not to call sys.exit or catch it.
There is some overlap with #389.
Related discussion: https://github.com/apify/apify-sdk-python/pull/390/files#r1948543716.
Currently, the
_ActorType.exit()method includes the following conditional check to preventsys.exit()from being executed during tests:This approach relies on environment variables to modify production code behavior, which is not ideal. Instead, tests should either configure the Actor to not to call
sys.exitor catch it.There is some overlap with #389.
Related discussion: https://github.com/apify/apify-sdk-python/pull/390/files#r1948543716.