I have been writing a testcase using pytest concerning a flask config file (flask.config.from_file) in which the file must be Json.
So I did this:
import pytest
from json import load as json_load
def test_config_file(app_client, config_client):
config_file= "./files/config.json"
app_client(config_file=config_file)
config_client.from_file(config_file ,load=json_load)
with open("/home/shayan/trystack/trystack/files/config.json", "r") as file:
config_dict = json_load(file)
assert config_file.endswith(".json") == True
BTW, I am a junior developer :)
here is my conftest.py:
@pytest.fixture
def app():
return create_app()
@pytest.fixture
def config_client(app):
return app.config
@pytest.fixture
def app_client():
return create_app
create_app gets config_file as an argument in my main module.
I want to check if config_file is Json or not. I have already checked the extension of config_file but what is the best-practice for checking the actual file being Json?
There is already a question about validating using raises but I am looking for other ones if possible.