Skip to content

test(ci): create a dummy ~/.python-gitlab.cfg file #2174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

JohnVillalovos
Copy link
Member

@JohnVillalovos JohnVillalovos commented Jul 23, 2022

Create a working ~/.python-gitlab.cfg file when running the unit
tests in the CI. This is to ensure our unit tests still work if a config file
exists.

@JohnVillalovos
Copy link
Member Author

Once PR #2173 is merged, then this will pass the CI.

@JohnVillalovos JohnVillalovos force-pushed the jlvillal/create_config branch 2 times, most recently from 9855d56 to 183d6ff Compare July 24, 2022 03:17
Create a working ~/.python-gitlab.cfg file when running the unit tests
in the CI. This is to ensure our unit tests still work if a config
file exists.
@JohnVillalovos JohnVillalovos force-pushed the jlvillal/create_config branch from 183d6ff to 0f4fa8f Compare July 29, 2022 04:48
@JohnVillalovos JohnVillalovos changed the title test: create a dummy ~/.python-gitlab.cfg file test(ci): create a dummy ~/.python-gitlab.cfg file Jul 29, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #2174 (0f4fa8f) into main (8ba97aa) will increase coverage by 4.00%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #2174      +/-   ##
==========================================
+ Coverage   91.56%   95.56%   +4.00%     
==========================================
  Files          81       81              
  Lines        5344     5344              
==========================================
+ Hits         4893     5107     +214     
+ Misses        451      237     -214     
Flag Coverage Δ
api_func_v4 81.41% <ø> (?)
cli_func_v4 83.06% <ø> (-0.10%) ⬇️
unit 87.31% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
gitlab/utils.py 98.59% <0.00%> (+1.40%) ⬆️
gitlab/v4/objects/members.py 94.82% <0.00%> (+1.72%) ⬆️
gitlab/client.py 98.70% <0.00%> (+3.44%) ⬆️
gitlab/types.py 98.21% <0.00%> (+3.57%) ⬆️
gitlab/v4/objects/notes.py 94.28% <0.00%> (+3.80%) ⬆️
gitlab/v4/objects/groups.py 89.40% <0.00%> (+3.97%) ⬆️
gitlab/v4/objects/pages.py 100.00% <0.00%> (+5.00%) ⬆️
gitlab/v4/objects/events.py 98.73% <0.00%> (+5.06%) ⬆️
gitlab/mixins.py 92.30% <0.00%> (+5.49%) ⬆️
gitlab/v4/objects/environments.py 100.00% <0.00%> (+5.88%) ⬆️
... and 21 more

@nejch
Copy link
Member

nejch commented Jul 29, 2022

We have since added #2187 where we ignore default files including /etc/python-gitlab.cfg now at root-level.

@JohnVillalovos
Copy link
Member Author

We have since added #2187 where we ignore default files including /etc/python-gitlab.cfg now at root-level.

True. But what if in the future we break it accidentally...

I don't have that strong of feelings about this but just thought a little extra safety.

@JohnVillalovos
Copy link
Member Author

It's fine with me if you want to go ahead and just close it 👍

@nejch
Copy link
Member

nejch commented Aug 22, 2022

I'm still thinking about what to do with it :D for me not having extra bash scripts would be nicer*, as it usually doesn't make sense to lint them and other contributors would then get comfortable and start adding more and more potentially, but I also get your point. Maybe also a tests/conftest.py fixture that is autoused and always first would be an option but probably also overkill.

*I'm biased because I removed a bunch of them https://github.com/python-gitlab/python-gitlab/tree/v2.2.0/tools :D

@nejch
Copy link
Member

nejch commented Oct 18, 2022

I think this could also be implemented as a top-level fixture, to keep things in one language and less code.

tests/conftest.py:

import os
from pathlib import Path

@pytest.fixture(autouse=True, scope="session")
def dummy_config() -> None:
    """
    Creates a dummy config file that should never affect our tests.
    See https://github.com/python-gitlab/python-gitlab/issues/2172.
    """
    config = Path.home() / ".python-gitlab.cfg"
    if config.exists() or "CI" not in os.environ:
        return

    config.write_text("""[global]
default = gitlab

[gitlab]
url = https://gitlab.example.com
private_token = not-a-valid-token
""")

    yield

    config.unlink(missing_ok=True)

For good measure, could also be included in the gitlab fixture then to ensure it's loaded first. https://stackoverflow.com/a/38611500/15836334

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants