jmvrbanac/Specter

Problems with example.py execution

Closed this issue · 2 comments

Hi,
I have implemented the Specter sample test example.py as a module. But, I am unable to see the test output with the specter shell command. I have Python2.7.3 version installed on my machine.

This is the output from the test execution:

Example.py:
from specter import Spec, expect

class SampleSpec(Spec):

"""Docstring describing the specification"""
def it_can_create_an_object(self):

    """ Test docstring"""
    expect('something').to.equal('something')

~

Log from console:
root@site-1-host-1-vm-1:/specter_tests#
root@site-1-host-1-vm-1:
/specter_tests# pwd
/root/specter_tests
root@site-1-host-1-vm-1:/specter_tests#
root@site-1-host-1-vm-1:
/specter_tests#
root@site-1-host-1-vm-1:/specter_tests# ls
spec
root@site-1-host-1-vm-1:
/specter_tests#
root@site-1-host-1-vm-1:~/specter_tests# specter

      ___
    _/ @@\
~- ( \  O/__     Specter
~-  \    \__)   ~~~~~~~~~~
~-  /     \     Keeping the Bogeyman away from your code!
~- /      _\
   ~~~~~~~~~

Traceback (most recent call last):
File "/usr/local/bin/specter", line 9, in
load_entry_point('Specter==0.2.1', 'console_scripts', 'specter')()
File "/usr/local/lib/python2.7/dist-packages/specter/runner.py", line 188, in activate
runner.run(args)
File "/usr/local/lib/python2.7/dist-packages/specter/runner.py", line 153, in run
module_name=self.arguments.select_module)
File "/usr/local/lib/python2.7/dist-packages/specter/scanner.py", line 38, in scan
classes = rlist_classes(module, cls_filter=Describe.plugin_filter)
File "/usr/local/lib/python2.7/dist-packages/pynsive/reflection.py", line 237, in rlist_classes
mnames = rlist_modules(module)
File "/usr/local/lib/python2.7/dist-packages/pynsive/reflection.py", line 179, in rlist_modules
module = import_module(mname)
File "/usr/local/lib/python2.7/dist-packages/pynsive/common.py", line 16, in import_module
return importlib.import_module(module_name)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
ImportError: No module named spec
root@site-1-host-1-vm-1:~/specter_tests#

Can you please let know the correct syntax for implementing a testcase in a Python module and executing it with Specter library? I am looking for something similar to Beaker Ruby test library where every test case is a .rb code block (an instance of a test case class).

Thanks in advance for your assistance.

Mihir

First and foremost, welcome to Specter!

From what you mentioned, it sounds like you're coming from Ruby. With that in mind, does the spec folder containing your test files have a file called __init__.py in it? Specter searches for tests within a Python package structure (defaults to the spec package). A Python package is defined by having a __init__.py file within a folder. Interestingly enough, this seems to be a rather common mistake when people are getting use to working with Python. Anyhow, I hope that this solves the issue you're seeing. If not, let me know and we can dig a bit deeper.

Thanks for the reply to my comment.

I can execute the tests now after defining all within init.py in the same spec dir.

:~/specter_tests# specter

      ___
    _/ @@\
~- ( \  O/__     Specter
~-  \    \__)   ~~~~~~~~~~
~-  /     \     Keeping the Bogeyman away from your code!
~- /      _\
   ~~~~~~~~~

Sample Spec
\u221f it can create an object


------- Summary --------
Pass | 1
Skip | 0
Fail | 0
Error | 0
Incomplete | 0
Test Total | 1

  • Expectations | 1

:~/specter_tests#