heynemann/pyvows — Issue #18: Topic's state is shared between tests ?
Author: eMxyzptlk
Created: 2012-01-31 20:26:17+00:00
State: open

Hello,

I'm new to pyVows (and to Python for that matter), I'm coming from Ruby but need to develop a module for work, That said, I'm a bit consused to find out that the state of the tested object (the topic) is being shared between tests.. Look at the code and the test output to know exactly what I mean

```python

from pyvows import Vows, expect

class Fixnum(object):
def __init__(self):
self.num = 0

def add(self, num):
self.num += num

@Vows.batch
class FixnumTest(Vows.Context):
def topic(self):
return Fixnum()

class Init(Vows.Context):
def should_be_numeric(self, topic):
expect(topic.num).to_be_numeric()

def should_init_to_zero(self, topic):
expect(topic.num).to_equal(0)

def should_be_able_to_change_number(self, topic):
topic.num = 9
expect(topic.num).to_equal(9)

class Add(Vows.Context):
def should_respond_to_add(self, topic):
expect(topic.add).to_be_a_function()

def should_be_able_to_add_a_number(self, topic):
topic.num = 1
topic.add(2)
expect(topic.num).to_equal(3)
```

```bash
$ pyvows /tmp/fixnum.py
============
Vows Results
============

Fixnum test
Init
✗ should init to zero
Expected topic(9) to equal 0.

Traceback (most recent call last):
File "/Users/wael/.pythonbrew/pythons/Python-2.7.2/lib/python2.7/site-packages/pyvows/runner.py", line 150, in async_run_vow
result = member(context_instance, topic)
File "/Users/wael/.pythonbrew/pythons/Python-2.7.2/lib/python2.7/site-packages/pyvows/runner.py", line 240, in wrapper
ret = method(*args, **kw)
File "/tmp/fixnum.py", line 20, in should_init_to_zero
expect(topic.num).to_equal(0)
File "/Users/wael/.pythonbrew/pythons/Python-2.7.2/lib/python2.7/site-packages/pyvows/core.py", line 52, in assert_topic
return getattr(Vows.Assert, method_name)(self.topic, *args, **kw)
File "/Users/wael/.pythonbrew/pythons/Python-2.7.2/lib/python2.7/site-packages/pyvows/core.py", line 171, in exec_assertion
raise VowsAssertionError(raw_msg, *args)
VowsAssertionError: Expected topic(9) to equal 0.

found in /tmp/fixnum.py at line 19

✗ OK » 4 honored • 1 broken (0.003353s)
```

Am i doing something wrong ?