python / python/cpython

Order-dependent failure: test_profiling CLI test fails after test_importlib.test_util

Aberta
#152,659 3 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

tests type-bug
Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

Bug report

Bug description:
Summary

I found an order-dependent test failure on current main.

A test_profiling sampling CLI test passes when run alone, but fails when run after test_importlib.test_util.

Environment
  • OS: Windows NT 10.0.26200.0
  • CPython commit: 449122ed0dbdb6a545af4927c59f4c80ee15c515
  • Debug build: PCbuild\amd64\python_d.exe
  • Release build: also reproduced
  • Branch: investigate/deep-cpython-bug-hunt
Reproduction
PCbuild\amd64\python_d.exe -m unittest -v test.test_importlib.test_util test.test_profiling.test_sampling_profiler.test_cli.TestSampleProfilerCLI.test_cli_module_argument_parsing

The same profiling test passes when run alone.

Actual behavior

The test fails with:

profiling.sampling.errors.SamplingModuleNotFoundError: Module 'mymodule' not found.
Expected behavior

The profiling CLI test should pass regardless of whether test_importlib.test_util ran earlier in the same process.

Investigation

The profiling CLI test patches:

importlib.util.find_spec

However, after running test_importlib.test_util, importlib.util and sys.modules["importlib.util"] appear to refer to different module objects.

The CLI code calls through its own imported module reference:

profiling.sampling.cli.importlib.util.find_spec

So the mock on the global importlib.util.find_spec does not intercept the lookup, and the CLI tries to resolve the fake module name normally.

That leads to:

SamplingModuleNotFoundError: Module 'mymodule' not found.

I could not find an existing open issue or PR covering this failure.

Possible fix

The smallest fix may be to patch the symbol at the point where it is used, for example:

profiling.sampling.cli.importlib.util.find_spec

inside the profiling CLI tests, or alternatively to avoid this mock by using a real temporary module.

I am happy to prepare a focused test-only PR if that direction sounds reasonable.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs
  • gh-152675

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece com test.test_importlib.test_util e test.test_profiling.test_sampling_profiler.test_cli.TestSampleProfilerCLI.test_cli_module_argument_parsing e, em seguida, execute o comando unittest reportado no Windows. Verifique o destino do mock em relação à referência do módulo usada por profiling.sampling.cli. A tarefa estará concluída quando o teste de CLI passar sozinho e depois de test_importlib.test_util; revise o PR vinculado gh-152675 para conferir o trabalho atual.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
testing-qa
Tipo de issue
Bug
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Estagnada
Clareza
Claramente especificada
Facilidade para iniciantes
25/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.