molotov icon indicating copy to clipboard operation
molotov copied to clipboard

AttributeError("module 'molotov' has no attribute 'get_context'",)

Open sssvad opened this issue 3 years ago • 2 comments

(env) root@xxx-001:/home/ubuntu/scalability/molotov# molotov -p2 -w 2 -d 20 -r 10 -x 1.py **** Molotov v2.1. Happy breaking! **** Forking 2 processes This is the end for 0 This is the end for 0 [9574] Preparing 2 workers...WORKERS: 0 [9573] Preparing 2 workers... [9573] OK [9574] OK [9574] AttributeError("module 'molotov' has no attribute 'get_context'",) [9574] File "/home/ubuntu/scalability/env/lib/python3.6/site-packages/molotov/worker.py", line 94, in session_setup [9573] AttributeError("module 'molotov' has no attribute 'get_context'",) [9573] File "/home/ubuntu/scalability/env/lib/python3.6/site-packages/molotov/worker.py", line 94, in session_setup [9574] await self._session_setup(self.wid, session) [9574] File "1.py", line 40, in init_session [9574] molotov.get_context(session).attach("ob", SomeObject(loop=session.loop)) [9573] await self._session_setup(self.wid, session) [9573] File "1.py", line 40, in init_session [9573] molotov.get_context(session).attach("ob", SomeObject(loop=session.loop)) This is the end of the test. WORKERS: 0 SUCCESSES: 0 | FAILURES: 0 *** Bye *** {'WORKER': 0, 'REACHED': 0, 'RATIO': 0.0, 'OK': 0, 'FAILED': 0, 'MINUTE_OK': 0, 'MINUTE_FAILED': 0, 'MAX_WORKERS': 2, 'SETUP_FAILED': 0, 'SESSION_SETUP_FAILED': 2} (env) root@xxx-001:/home/ubuntu/scalability/molotov#

sssvad avatar Mar 30 '21 21:03 sssvad

File: 1.py

"""

This Molotov script has:

  • a global setup fixture that sets variables
  • an init worker fixture that sets the session headers
  • an init session that attachs an object to the current session
  • 1 scenario
  • 2 tear downs fixtures

""" import molotov

class SomeObject(object): """Does something smart in real life with the async loop. """

def __init__(self, loop):
    self.loop = loop

def cleanup(self):
    pass

@molotov.global_setup() def init_test(args): molotov.set_var("SomeHeader", "1") molotov.set_var("endpoint", "http://localhost:8080")

@molotov.setup() async def init_worker(worker_num, args): headers = {"AnotherHeader": "1", "SomeHeader": molotov.get_var("SomeHeader")} return {"headers": headers}

@molotov.setup_session() async def init_session(worker_num, session): molotov.get_context(session).attach("ob", SomeObject(loop=session.loop))

@molotov.scenario(100) async def scenario_one(session): endpoint = molotov.get_var("endpoint") async with session.get(endpoint) as resp: res = await resp.json() assert res["result"] == "OK" assert resp.status == 200

@molotov.teardown_session() async def end_session(worker_num, session): molotov.get_context(session).ob.cleanup()

@molotov.teardown() def end_worker(worker_num): print("This is the end for %d" % worker_num)

@molotov.global_teardown() def end_test(): print("This is the end of the test.")

sssvad avatar Mar 30 '21 21:03 sssvad

Hi, that function didn't yet exist at the time of molotov-2.1 but I get you used an example scenario as a template from a newer source version. Simply update your molotov installation!

n1ngu avatar Aug 23 '21 15:08 n1ngu

Thanks @n1ngu

tarekziade avatar Oct 07 '22 03:10 tarekziade