This documentation provides a step-by-step guide for running tests for the kubernetes-client/python project. The tests are structured to verify the functionality and reliability of the codebase.
Prerequisites
Before running the tests, ensure that you have the following prerequisites in place:
- Python Environment: Ensure that you have Python installed (Python 3.6 or later is recommended).
- pip: Make sure you have pip to install necessary packages.
Step 1: Clone the Repository
First, clone the repository to your local machine:
git clone https://github.com/python-kubernetes/client-python.git
cd client-python
Step 2: Install Test Requirements
Navigate to the appropriate directory and install the test requirements specified in test-requirements.txt
:
pip install -r test-requirements.txt
The test-requirements.txt
file includes various dependencies such as:
coverage>=4.0.3
nose>=1.3.7
pytest
pytest-cov
pluggy>=0.3.1
py>=1.4.31
randomize>=0.13
sphinx>=1.4
recommonmark
sphinx_markdown_tables
pycodestyle
autopep8
isort
Step 3: Running Tests
The test suite can be executed using the pytest
framework. You can run the tests by executing the following command from the root directory of your cloned repository:
pytest
Running Specific Tests
To run specific tests, you can specify the path to the test module or individual test case. For example, if you want to run tests located in kubernetes/base/config/kube_config_test.py
, you can do so with:
pytest kubernetes/base/config/kube_config_test.py
Using Coverage
If you want to check the test coverage, you can use the --cov
flag along with pytest:
pytest --cov=kubernetes
This will provide you with a coverage report indicating how much of the code is being tested.
Running All Tests with Coverage
To run all tests and generate a coverage report at once, you can combine the commands:
pytest --cov=kubernetes --cov-report=html
This command will also generate an HTML report of the test coverage.
Step 4: Viewing Test Results
Upon running the tests, pytest
will summarize the results in the terminal, showing how many tests passed, failed, or were skipped.
To view the coverage report in HTML format, navigate to the htmlcov
directory created in your project root and open index.html
in your web browser.
Additional Testing Utilities
The project includes several test modules. Each of these modules can be executed directly, utilizing the unittest
framework if desired.
For example, to run all tests in kubernetes/base/config/exec_provider_test.py
, use:
python -m unittest kubernetes.base.config.exec_provider_test
This approach can also be applied to other test files:
python -m unittest kubernetes.base.stream.ws_client_test
Conclusion
You are now equipped with the knowledge to effectively run tests within the kubernetes-client/python project. Utilizing pytest along with coverage tools ensures that you maintain high code quality and reliability.
References:
- File: doc/README.md
- File: test-requirements.txt
- File: kubernetes/base/config/kube_config_test.py
- File: kubernetes/base/config/exec_provider_test.py
- File: kubernetes/base/stream/ws_client_test.py