unable to add own extension with generator in pyresttest

307 Views Asked by At

I am investigating usage of pyresttest for testing our api calls also new to python and stuck a bit on:

  • have a file with generator:

     import pyresttest.validators as validators
     from pyresttest.binding import Context
     import sys
     import datetime
    
    
     def get_current_date_time():
         return datetime.datetime.now().isoformat()
    
    
     GENERATORS = {'date': get_current_date_time}
    

when i run this command, to use generator in my test case

pyresttest http://localhost:8181/ generator_test.yaml --import_extension 'date'

I got this:

 Traceback (most recent call last):   File "/usr/local/bin/pyresttest",
 line 4, in <module>
     __import__('pkg_resources').run_script('pyresttest==1.7.2.dev0', 'pyresttest')   File
 "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py",
 line 739, in run_script
     self.require(requires)[0].run_script(script_name, ns)   File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py",
 line 1494, in run_script
     exec(code, namespace, namespace)   File "/usr/local/lib/python2.7/site-packages/pyresttest-1.7.2.dev0-py2.7.egg/EGG-INFO/scripts/pyresttest",
 line 4, in <module>
     resttest.command_line_run(sys.argv[1:])   File "/usr/local/lib/python2.7/site-packages/pyresttest-1.7.2.dev0-py2.7.egg/pyresttest/resttest.py",
 line 914, in command_line_run
     main(args)   File "/usr/local/lib/python2.7/site-packages/pyresttest 1.7.2.dev0-py2.7.egg/pyresttest/resttest.py",
 line 815, in main
     register_extensions(extensions)   File "/usr/local/lib/python2.7/site-packages/pyresttest-1.7.2.dev0-py2.7.egg/pyresttest/resttest.py",
 line 748, in register_extensions
     module = __import__(ext, globals(), locals(), package) ImportError: No module named date

Am I missing something simple or it is a typo somewhere? Thanks.

1

There are 1 best solutions below

0
Mariia Vitiuk On

I see now my mistake :) I need to use name of the *.py file in --import_extensions.
like:

resttest.py https://api.github.com extension_use_test.yaml --import_extensions '[name_of_the_file_py_with_extensions]'