Mocking gitlab in python

I have a script that uses git to install other GitLab programs. I have been able to create unit tests for git by creating a local and ‘remote’ repo on my local machine. This way I can test my git related code without requiring git to be up. Is there a way I can do a similar thing for GitLab in python.

Hi,

Can you please share the structure of this script? I am not sure if I am follow your intentions here. Maybe also what you mean specifically with mocking GitLab in Python - is that a mock for the Git server API, or likewise?

Cheers,
Michael

Yes it is a mock for the Git server API using this allows me to test all of my code apart from this line

 f'git clone -b {branch} --single-branch https://{deploy_token_username}:{deploy_token}@gitlab.com

Is there a way I can run this command without actually interacting with the GitLab servers

Hi,

there is a great Python library for using the REST API. Their code includes tests where they seem to mock the HTTP server for specific requests.

You should be able to adopt and implement this by yourself. Another option I could think of would be starting off your own development instance of GitLab. This is described in the contributing docs:

Cheers,
Michael