pre_run for Reports #6057

Closed
opened 2025-12-29 19:36:10 +01:00 by adam · 3 comments
Owner

Originally created by @hagbarddenstore on GitHub (Feb 7, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.1.7

Feature type

New functionality

Proposed functionality

Add a new function stub to the Reports class to be executed before any tests are executed.

Use case

If you're running multiple tests against the same dataset, it would be beneficial to be able to load the dataset once instead of loading it per test.

Example:

For each virtual machine, validate that vCPUs is set, validate that memory is set, validate that platform is set, validate that a primary IP is set, etc.

All of them are executed against the same dataset, which is loaded multiple times.

Database changes

None

External dependencies

None

Originally created by @hagbarddenstore on GitHub (Feb 7, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.1.7 ### Feature type New functionality ### Proposed functionality Add a new function stub to the `Reports` class to be executed before any tests are executed. ### Use case If you're running multiple tests against the same dataset, it would be beneficial to be able to load the dataset once instead of loading it per test. Example: For each virtual machine, validate that vCPUs is set, validate that memory is set, validate that platform is set, validate that a primary IP is set, etc. All of them are executed against the same dataset, which is loaded multiple times. ### Database changes None ### External dependencies None
adam added the status: acceptedtype: feature labels 2025-12-29 19:36:10 +01:00
adam closed this issue 2025-12-29 19:36:10 +01:00
Author
Owner

@bistraque commented on GitHub (Feb 7, 2022):

You can simply override the run method. Something like:

def run(self, job_result):
    # retrieve your data
    data = ...
    # store it in report object, test_xxx() methods can access it when called
    self.data = data
    super().run(job_result)
@bistraque commented on GitHub (Feb 7, 2022): You can simply override the `run `method. Something like: ``` def run(self, job_result): # retrieve your data data = ... # store it in report object, test_xxx() methods can access it when called self.data = data super().run(job_result) ```
Author
Owner

@jeremystretch commented on GitHub (Feb 7, 2022):

@bistraque is correct in that this can be accomplished by overriding the run() method, although I think there's a valid argument to introduce pre_run() as a convenience method given that we already have post_run() for a similar purpose.

@jeremystretch commented on GitHub (Feb 7, 2022): @bistraque is correct in that this can be accomplished by overriding the `run()` method, although I think there's a valid argument to introduce `pre_run()` as a convenience method given that we already have `post_run()` for a similar purpose.
Author
Owner

@jeremystretch commented on GitHub (Feb 7, 2022):

I'm going to tag this for v3.2. I'm not comfortable implementing it in a v3.1.x release as it has the potential to be a breaking change (i.e. for any script which already defines a pre_run() method).

@jeremystretch commented on GitHub (Feb 7, 2022): I'm going to tag this for v3.2. I'm not comfortable implementing it in a v3.1.x release as it has the potential to be a breaking change (i.e. for any script which already defines a `pre_run()` method).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6057