Skip to content

Is it possible to test threads with async topic? #128

@aldefalco

Description

@aldefalco

I tried to test following:

from pyvows import Vows, expect
from threading import Thread
from time import sleep

class MyThread(Thread):

    def __init__(self, a, b, done):
        super(MyThread, self).__init__()
        self.a = a
        self.b = b
        self.done = done

    def run(self):
        while True:
            sleep(2)
            self.done(self.a+self.b)
            break

def sum_in_thread(a, b, callback):
    t = MyThread(a, b, callback)
    t.start()

def sum(a, b, callback):
    callback(a+b)

@Vows.batch
class ThreadContext(Vows.Context):
    @Vows.async_topic
    def topic(self, callback):
        sum_in_thread(2,2, callback)
        #sum(2,2, callback)

    def should_equal_to_4(self, topic):
        expect(topic[0]).to_equal(4)

It passed but with 0 honored. Is it possible to test this case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions