0

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.

pvg
  • 2,673
  • 4
  • 17
  • 31
  • Maybe `import_extension` does something other than what you think it does? – pvg Mar 08 '17 at 21:23
  • According to this doc https://github.com/svanoort/pyresttest/blob/master/extensions.md -> Extensions are specified for loadin at runtime with the --import_extensions argument it is exactly for that purpose. And I've tried solution suggested in the example with the project . `resttest.py https://api.github.com extension_use_test.yaml --import_extensions 'sample_extension' Test Group Successful SUCCEEDED: : 3/3 Tests Passed!` - works good. I'm very confused now. – Mariia Vitiuk Mar 09 '17 at 09:00

1 Answers1

1

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]'