|
| 1 | +Getting Started |
| 2 | +============== |
| 3 | + |
| 4 | +This guide will help you get started with development on pynetbox. It covers setting up your development environment and running tests. |
| 5 | + |
| 6 | +Development Environment |
| 7 | +--------------------- |
| 8 | + |
| 9 | +1. Fork the pynetbox repository on GitHub |
| 10 | +2. Clone your fork locally |
| 11 | +3. Create a virtual environment and install development dependencies: |
| 12 | + |
| 13 | +.. code-block:: bash |
| 14 | +
|
| 15 | + python -m venv venv |
| 16 | + source venv/bin/activate # On Windows: venv\Scripts\activate |
| 17 | + pip install -e ".[dev]" |
| 18 | +
|
| 19 | +Running Tests |
| 20 | +------------ |
| 21 | + |
| 22 | +pynetbox uses pytest for testing. The test suite includes both unit tests and integration tests. |
| 23 | + |
| 24 | +Unit Tests |
| 25 | +~~~~~~~~~ |
| 26 | + |
| 27 | +To run the unit tests: |
| 28 | + |
| 29 | +.. code-block:: bash |
| 30 | +
|
| 31 | + pytest tests/unit |
| 32 | +
|
| 33 | +Integration Tests |
| 34 | +~~~~~~~~~~~~~~~ |
| 35 | + |
| 36 | +The integration tests require a running NetBox instance. The test suite uses pytest-docker to spin up NetBox instances in Docker containers. |
| 37 | + |
| 38 | +To run the integration tests: |
| 39 | + |
| 40 | +.. code-block:: bash |
| 41 | +
|
| 42 | + pytest tests/integration |
| 43 | +
|
| 44 | +You can specify which versions of NetBox to test against using the `--netbox-versions` flag: |
| 45 | + |
| 46 | +.. code-block:: bash |
| 47 | +
|
| 48 | + pytest tests/integration --netbox-versions 4.1 4.2 4.3 |
| 49 | +
|
| 50 | +Running Specific Tests |
| 51 | +~~~~~~~~~~~~~~~~~~~~ |
| 52 | + |
| 53 | +You can run specific test files or test functions: |
| 54 | + |
| 55 | +.. code-block:: bash |
| 56 | +
|
| 57 | + # Run a specific test file |
| 58 | + pytest tests/unit/test_api.py |
| 59 | +
|
| 60 | + # Run a specific test function |
| 61 | + pytest tests/unit/test_api.py::test_api_status |
| 62 | +
|
| 63 | + # Run tests matching a pattern |
| 64 | + pytest -k "test_api" |
| 65 | +
|
| 66 | +Test Coverage |
| 67 | +~~~~~~~~~~~ |
| 68 | + |
| 69 | +To run tests with coverage reporting: |
| 70 | + |
| 71 | +.. code-block:: bash |
| 72 | +
|
| 73 | + pytest --cov=pynetbox tests/ |
| 74 | +
|
| 75 | +Submitting Pull Requests |
| 76 | +---------------------- |
| 77 | + |
| 78 | +Once you're happy with your work and have verified that all tests pass, commit your changes and push it upstream to your fork. Always provide descriptive (but not excessively verbose) commit messages. Be sure to prefix your commit message with the word "Fixes" or "Closes" and the relevant issue number (with a hash mark). This tells GitHub to automatically close the referenced issue once the commit has been merged. |
| 79 | + |
| 80 | +.. code-block:: bash |
| 81 | +
|
| 82 | + git commit -m "Closes #1234: Add IPv5 support" |
| 83 | + git push origin |
| 84 | +
|
| 85 | +Once your fork has the new commit, submit a pull request to the pynetbox repo to propose the changes. Be sure to provide a detailed accounting of the changes being made and the reasons for doing so. |
| 86 | + |
| 87 | +Once submitted, a maintainer will review your pull request and either merge it or request changes. If changes are needed, you can make them via new commits to your fork: The pull request will update automatically. |
| 88 | + |
| 89 | +.. warning:: |
| 90 | + Remember, pull requests are permitted only for **accepted** issues. If an issue you want to work on hasn't been approved by a maintainer yet, it's best to avoid risking your time and effort on a change that might not be accepted. (The one exception to this is trivial changes to the documentation or other non-critical resources.) |
0 commit comments