Skip to content
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

Pytest cannot be run using the custom command in the mian method #290

Open
longweiqiang opened this issue Apr 30, 2022 · 1 comment
Open

Comments

@longweiqiang
Copy link

conftest.py

import pytest
from simple_settings import settings

def pytest_addoption(parser):
    parser.addoption('--settings',
                     action='store',
                     default='config.env_qa')

test.py

import pytest
from simple_settings import settings

@pytest.mark.httptest_p0
class TestBotJobCase(TestBase):

    @pytest.mark.parametrize("args", data_item, ids=id_item)
    def test_bot_get_job_case(self, args):
        res = HttpUtils.http_get(self.headers, settings.JOB_BASE_URL+self.url_path, args['params'])

run.py

import pytest

if __name__ == '__main__':
    pytest.main(['--settings=config.env_qa', "-m", "httptest_p0", "--html=./testoutput/report.html"])

Errors

image

@Drachenfels
Copy link

Drachenfels commented Jun 20, 2023

This has no chance of working, as it's your script is swallowing all command line arguments.

Run python run.py

>               raise RuntimeError("Settings are not configured")
E               RuntimeError: Settings are not configured

Now try: pytest --settings=config.env_qa tests/

tests/test_some.py .                                                                                                                   [100%]

============================================================= 1 passed in 0.01s ==============================================================

If you want to wrap your script within run.py, use env variable:

run.py

import os

import pytest

if __name__ == "__main__":
    os.environ["SIMPLE_SETTINGS"] = "app.env_qa"
    pytest.main(["tests/"])

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

No branches or pull requests

2 participants