Pytest tests cannot load global config that definitely exists even though real use of the library can
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 48/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Pouca atividade
- Stack de tecnologia
- git, python
- Domínio
- testing-qa
Direção de pesquisa
Comece com test/test_config.py e com os caminhos Config.get_global_config e Config.get_system_config mostrados em pygit2/config.py. Reproduza os testes ignorados com pytest e compare a visibilidade dos arquivos de configuração e as mensagens de erro com os exemplos interativos de Python. O trabalho estará concluído quando os testes não relatarem mais silenciosamente, de forma incorreta, arquivos de configuração existentes, ou documentarem e relatarem claramente a limitação do ambiente.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
While working on and writing tests for #1466, I discovered that Config.get_global_config raised an IOError in my test. Confused as to why that didn't break other tests, I searched for use of this in the tests and found this:
def test_global_config() -> None:
try:
assert Config.get_global_config() is not None
except IOError:
# There is no user config
pass
def test_system_config() -> None:
try:
assert Config.get_system_config() is not None
except IOError:
# There is no system config
pass
I changed these tests to this so that these situations result in an official "skip" with information about why it was skipped, instead of just silently fake-passing:
def test_global_config() -> None:
try:
assert Config.get_global_config() is not None
except IOError as e:
settings = Settings()
pytest.skip(f'Unavailable for testing with home dir = {settings.homedir}: {e}')
def test_system_config() -> None:
try:
assert Config.get_system_config() is not None
except IOError as e:
pytest.skip(f'Unavailable for testing: {e}')
But the resulting pytest output puzzled me:
test/test_config.py::test_global_config SKIPPED (Unavailable for testing with home dir = /Users/nicholas: the global file '.gitconfig' doesn't exist:)
test/test_config.py::test_system_config SKIPPED (Unavailable for testing: the system file 'gitconfig' doesn't exist:)
The first reason it puzzled me is that /Users/nicholas/.gitconfig definitely exists:
$ ls -al /Users/nicholas/.gitconfig
-rw-r--r-- 1 nicholas staff 366 Apr 9 17:39 /Users/nicholas/.gitconfig
The second reason it puzzled me is that I don't encounter this error if I simply use the library in a Python shell prompt:
>>> c = pygit2.Config.get_global_config()
>>> c["push.gpgSign"]
'if-asked'
Now, it's correct that my system config file does not exist:
>>> pygit2.Config.get_system_config()
Traceback (most recent call last):
File "<python-input-8>", line 1, in <module>
pygit2.Config.get_system_config()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/Users/nicholas/Development/OSS/libgit2/pygit2/.venv/lib/python3.14/site-packages/pygit2/config.py", line 309, in get_system_config
check_error(err)
~~~~^^^^^
File "/Users/nicholas/Development/OSS/libgit2/pygit2/.venv/lib/python3.14/site-packages/pygit2/config.py", line 300, in _from_found_config
File "/Users/nicholas/Development/OSS/libgit2/pygit2/.venv/lib/python3.14/site-packages/pygit2/errors.py", line 56, in check_error
raise IOError(message)
OSError: the system file 'gitconfig' doesn't exist: No such file or directory
But note that that error message is slightly different from the skip message of the test: "No such file or directory" is missing in the skip message. Weird?
If I now manually create /etc/gitconfig:
>>> c = pygit2.Config.get_system_config()
>>> c["bogus.foo"]
'bar'
But, low and behold, that test, also, still skips with the same partial message about not finding the system config file.
So, these two functions do work ... just not in tests. I've been unable to figure out why. My best guess is that mypy is somehow sandboxed so that it can't read these files? But that's just a wild guess. I can't confirm it.
- Linguagem predominante
- Python
- Estrelas
- 1.7k
- Forks
- 408
- Merge médio
- 2d 57min
- PRs com merge (30d)
- 7
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de libgit2/pygit2
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
-
merge_bases not wrapped Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 48/100
Todas as issues de libgit2/pygit2
Issues semelhantes
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
zostera/django-bootstrap4#894 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
use-agent-os/agent-os#3276 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
NousResearch/hermes-agent#117848 ·