question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allowing custom options to passed into tests?

See original GitHub issue

I’m just starting using locust to test our application. Our application can have slugs in the URL that I want to test against. Rather than have to change the task file to put in a new slug to test, I hacked locust to have a -o key value (or --option key value) command line options that will be available in the task as self.options[key].

I’ve done some work on this branch: https://github.com/rory/locust/tree/custom-options (see the diff here https://github.com/rory/locust/compare/master...custom-options ). I haven’t requested a pull yet because I’m unsure if I’m doing it in a sensible way. I haven’t tested this using the master/slave/distributed workflow, since we’re not using that yet.

Can you tell me if this is a good feature others might want, and if I’m doing it in a good way?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:1
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
heymancommented, May 18, 2016

@crysyn The args and kwargs are set when scheduling a nested TaskSet using TaskSet.schedule_task() (http://docs.locust.io/en/latest/api.html#locust.core.TaskSet.schedule_task).

Can’t you set an environment variable when starting locust like this:

$ env MY_VAR=1 locust -f testfile.py [...]

and then read it in your test script like this

import os

class MyTaskSet(TaskSet):
    def some_task(self):
        if os.environ.get("MY_VAR"):
            ...

You would still need to restart Locust, but at least you don’t need to change the python code.

2reactions
DenisKuplyakovcommented, Aug 29, 2017

Env vars is the one of the worst workarounds, because you need to read code of the test to known which env vars you should pass. Arguments for a script with adequate help messages and stuff like default and required will be useful. I think that options parsing should be moved to argparse and some on_setup interface should be exposed to populate parser with additional own parameters.

Or there will be a problems with distributed version in such case? Anyway env vars doesn’t look better at such situation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

3 ways to work with custom settings in an Apex unit test
1. Create the custom setting data. Insert the required custom setting data in your test just like any other test data. Either in...
Read more >
unittest — Unit testing framework — Python 3.11.1 ...
Ran 3 tests in 0.000s OK. Passing the -v option to your test script will instruct unittest.main() to enable a higher level of...
Read more >
Configuring custom fields
TestRail currently supports custom fields for two entities, namely for test cases and test results. Custom fields for test cases allow you ...
Read more >
googletest/advanced.md at main
This allows you to customize how the value appears in googletest's output without affecting code that relies on the behavior of its <<...
Read more >
Test Configuration Options
This page provides a reference for the valid test configuration options (capabilities) you can set to specify the variable settings for your automated...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found