pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
12.11k stars 2.68k forks source link

Running tests from wheel package with --pyargs ignores custom arguments #3517

Closed fkromer closed 5 years ago

fkromer commented 6 years ago

I created a test only package like described here (wheel, tests deployed via data_package=). I noticed that if the tests are run on Ubuntu with pytest --pyargs <package-name> <custom-arguments> the tests are detected and run but they fail during setup because the custom command line arguments are not recognized from conftest.py. I found a workaround for this issue. Is this the recommended way to handle this my use case (deploy test only package with custom command line arguments)?

pytestbot commented 6 years ago

GitMate.io thinks possibly related issues are https://github.com/pytest-dev/pytest/issues/821 (Running py.test without arguments raises missing argument error), https://github.com/pytest-dev/pytest/issues/3198 (Ignore individual tests), https://github.com/pytest-dev/pytest/issues/1484 (running py.test), https://github.com/pytest-dev/pytest/issues/2371 (Running tests inside namespace packages ?), and https://github.com/pytest-dev/pytest/issues/2544 (Run tests truly programmatically).

RonnyPfannschmidt commented 6 years ago

those need to be an actual pytest plugin in that case - early conftests are not discovered in packages

fkromer commented 6 years ago

@RonnyPfannschmidt Thx for saving me time otherwise wasted for unsuccessful exploration :slightly_smiling_face:

I know about pytest-dev/cookiecutter-pytest-plugin which creates a structure like this (only files relevant for this issue shown):

pytest-awesome/
├── pytest_awesome.py
├── setup.py
├── tests
│   ├── conftest.py
│   └── test_awesome.py
└── tox.ini

If I consider the exemplary test only package structure (inclusive their utilities, ideally importable by other packages/pytest-plugins, etc.):

In essence: Is there something preventing me from structuring the package like following for a "easy" and a "full-blown" case?

Easy case with separate fixtures and utils:

pytest-awesome/
├── pytest_awesome.py
├── setup.py
├── fixtures.py
├── test_fixtures.py
├── utils.py
├── test_utils.py
├── tests
│   ├── conftest.py
│   └── test_awesome.py
└── tox.ini

Full-blown case with separate fixtures and utils:

pytest-awesome/
├── pytest_awesome.py
├── setup.py
├── fixtures
│   ├── fixtures_a.py
│   └── fixtures_b.py
├── utils
│   ├── utils_a.py
│   └── utils_b.py
├── plugin_tests
├──── fixtures
│        ├── test_fixtures_a.py
│        └── test_fixtures_b.py
├──── utils
│        ├── test_utils_a.py
│        └── test_utils_b.py
├── tests
│   ├── conftest.py
│   └── test_awesome.py
└── tox.ini
Zac-HD commented 5 years ago

Closing as inactive.