Skip to content

_reload_instrumentation_loader sometimes doesn't catch import errors #96

Open
@BergLucas

Description

@BergLucas

Describe the bug
In the C-modules benchmark, there are several runs where the _reload_instrumentation_loader function does not catch some exceptions when reloading a module, even though there is a try-except:

try:
importlib.reload(module)
except Exception as e: # noqa: BLE001
_LOGGER.warning("Reload of module {module.__name__} failed: %s", e)
However, when I reproduce the run on my PC, the exceptions are caught by the try-except.

Therefore, it might be interesting to investigate why this happens in some cases but not in others. I think it's mainly due to an environment configuration problem, but I'm not sure.

To Reproduce
Steps to reproduce the behaviour:

  1. Use Pynguin version '0.41.0'
  2. Use the following (minimal) code as a subject for test generation:

Install tensorflow==2.19.0 and target the module tensorflow.python.data.experimental.ops.interleave_ops.

  1. Use the following command line arguments to Pynguin:

--algorithm DYNAMOSA --allow_stale_assertions False --any_weight 5 --assertion_generation NONE --bytes_length 20 --call_llm_for_uncovered_targets False --call_llm_on_stall_detection False --change_parameter_probability 0.1 --chop_max_length True --chromosome_length 40 --collection_size 5 --configuration_id subprocess --constant_seeding True --coverage_metrics BRANCH --coverage_threshold 1 --create_coverage_report True --crossover_rate 0.75 --dynamic_constant_seeding True --elite 1 --enable_response_caching False --exploitation_starts_at_percent 0.5 --export_strategy PY_TEST --filter_covered_targets_from_test_cluster False --float_precision 0.01 --focused_config.number_of_mutations 10 --focused_config.number_of_tests_per_target 1 --focused_config.random_test_or_from_archive_probability 0.0 --format_with_black False --hybrid_initial_population False --initial_config.number_of_mutations 1 --initial_config.number_of_tests_per_target 10 --initial_config.random_test_or_from_archive_probability 0.5 --initial_population_mutations 0 --initial_population_seeding False --insertion_uut 0.5 --llm_test_case_percentage 0.5 --max_attempts 1000 --max_delta 20 --max_dynamic_length 1000 --max_dynamic_pool_size 50 --max_initial_tests 10 --max_int 2048 --max_length_test_case 2500 --max_llm_interventions 1 --max_plateau_len 25 --max_recursion 10 --max_sequence_length 10 --max_sequences_combined 10 --max_size 100 --maximum_coverage 100 --maximum_coverage_plateau -1 --maximum_iterations -1 --maximum_memory 3000 --maximum_search_time 600 --maximum_slicing_time 600 --maximum_statement_executions -1 --maximum_test_execution_timeout 5 --maximum_test_executions -1 --min_initial_tests 1 --minimum_coverage 100 --minimum_plateau_iterations -1 --model_name gpt-4o-mini --module_name tensorflow.python.data.experimental.ops.interleave_ops --mutation_order 1 --mutation_strategy FIRST_ORDER_MUTANTS --negate_type 0.1 --none_weight 1 --number_of_mutations 1 --object_reuse_probability 0.9 --original_type_weight 5 --output_path output --output_variables TargetModule ConfigurationId RunId ProjectName TotalTime AlgorithmIterations Coverage RandomSeed CoverageTimeline --population 50 --post_process True --primitive_reuse_probability 0.5 --project_name tensorflow --project_path . --random_perturbation 0.2 --rank_bias 1.7 --report_dir output --run_id 5220-16 --seed 26 --seed_from_archive False --seed_from_archive_mutations 3 --seed_from_archive_probability 0.2 --seeded_dynamic_values_reuse_probability 0.6 --seeded_primitives_reuse_probability 0.2 --seeded_testcases_reuse_probability 0.9 --selection TOURNAMENT_SELECTION --skip_optional_parameter_probability 0.7 --statement_insertion_probability 0.5 --statistics_backend CSV --string_length 20 --temperature 0.8 --test_change_probability 0.3333333333333333 --test_delete_probability 0.3333333333333333 --test_execution_time_per_statement 1 --test_insert_probability 0.3333333333333333 --test_insertion_probability 0.1 --timeline_interpolation True --timeline_interval 1000000000 --tournament_size 5 --type4py_weight 10 --type_guess_top_n 10 --type_inference_strategy TYPE_HINTS --type_tracing 0.0 --type_tracing_kept_guesses 2 --type_tracing_weight 10 --use_archive False --use_random_object_for_call 0.1 --wrap_var_param_type_probability 0.7 -v --subprocess

  1. Give the error (stack trace, etc) you are encountering:
[08:27:26] [Info] (pynguin.generator:run_pynguin:127): Stop Pynguin Test Generation…
Traceback (most recent call last):
  File "/usr/local/bin/pynguin", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/site-packages/pynguin/cli.py", line 213, in main
    return run_pynguin().value
  File "/usr/local/lib/python3.10/site-packages/pynguin/generator.py", line 125, in run_pynguin
    return _run()
  File "/usr/local/lib/python3.10/site-packages/pynguin/generator.py", line 545, in _run
    tracked_metrics = _track_final_metrics(
  File "/usr/local/lib/python3.10/site-packages/pynguin/generator.py", line 446, in _track_final_metrics
    _reload_instrumentation_loader(
  File "/usr/local/lib/python3.10/site-packages/pynguin/generator.py", line 382, in _reload_instrumentation_loader
    importlib.reload(module)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 169, in reload
    _bootstrap._exec(spec, module)
  File "<frozen importlib._bootstrap>", line 619, in _exec
  File "/usr/local/lib/python3.10/site-packages/pynguin/instrumentation/machinery.py", line 60, in exec_module
    super().exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/local/lib/python3.10/site-packages/tensorflow/python/data/experimental/ops/interleave_ops.py", line 261, in <module>
    v2_compat.register_data_v2_callback(_tf2_callback)
  File "/usr/local/lib/python3.10/site-packages/tensorflow/python/compat/v2_compat.py", line 36, in register_data_v2_callback
    _DATA_V2_CALLBACKS.register(data_v2_func, data_v2_func.__module__)
  File "/usr/local/lib/python3.10/site-packages/tensorflow/python/framework/registry.py", line 57, in register
    raise KeyError(
KeyError: "Registering two data_v2_callbacks with name 'tensorflow.python.data.experimental.ops.interleave_ops'! (Previous registration was in register /usr/local/lib/python3.10/site-packages/tensorflow/python/framework/registry.py:65)"
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: unable to join session keyring: unable to create session key: disk quota exceeded: unknown.

from the C-modules benchmark run 5220-16

Expected behavior

INFO     Stopping condition reached                                                                                                                                                                                         generator.py:565
INFO     Used search time: 601/600                                                                                                                                                                                          generator.py:567
INFO     Used memory: 1891.84375/3000.0 MB                                                                                                                                                                                  generator.py:567
INFO     Stop generating test cases                                                                                                                                                                                         generator.py:568
WARNING  Reload of module {module.__name__} failed: "Registering two data_v2_callbacks with name 'tensorflow.python.data.experimental.ops.interleave_ops'! (Previous registration was in register                           generator.py:415
        /home/lucas/.conda/envs/pynguin/lib/python3.10/site-packages/tensorflow/python/framework/registry.py:65)"                                                                                                         
INFO     Calculating resulting FinalBranchCoverage                                                                                                                                                                          generator.py:489
INFO     Written 6 test cases to /output/test_tensorflow_python_data_experimental_ops_interleave_ops.py                                                                                                                     generator.py:832
INFO     Writing statistics                                                                                                                                                                                                     stats.py:363
INFO     Stop Pynguin Test Generation…                                                                                                                                                                                      generator.py:129

Software Version (please complete the following information):

  • OS: Fedora 42
  • Python version: 3.10
  • Pynguin Version: 0.41.0

Additional info
There's also a bug in the call to the log function:

_LOGGER.warning("Reload of module {module.__name__} failed: %s", e)

The string is supposed to be an f-string to format the module name in the string, but since it isn't, it just displays {module.__name__}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions