Error on discovery #95

Closed
rubik opened this Issue Jun 27, 2012 · 22 comments

Projects

None yet

4 participants

@rubik
Contributor
rubik commented Jun 27, 2012
$ ls
...  README.txt  setup.py  testit.yml  tests  tox.ini ...
$ testify tests
Traceback (most recent call last):
  File "/home/miki/exp/bin/testify", line 25, in <module>
    test_program.TestProgram()
  File "/home/miki/exp/lib/python2.7/site-packages/testify/test_program.py", line 276, in __init__
    result = runner.run()
  File "/home/miki/exp/lib/python2.7/site-packages/testify/test_runner.py", line 128, in run
    for test_case in self.discover():
  File "/home/miki/exp/lib/python2.7/site-packages/testify/test_runner.py", line 103, in discover
    discovered_tests = list(discover_inner())
  File "/home/miki/exp/lib/python2.7/site-packages/testify/test_runner.py", line 97, in discover_inner
    debugger=self.debugger,
  File "/home/miki/exp/lib/python2.7/site-packages/testify/test_case.py", line 161, in __init__
    self.__init_fixture_methods()
  File "/home/miki/exp/lib/python2.7/site-packages/testify/test_case.py", line 220, in __init_fixture_methods
    method = fixture_decorator(method)
  File "/home/miki/exp/lib/python2.7/site-packages/testify/test_case.py", line 590, in fixture_decorator
    function._fixture_type = fixture_type
AttributeError: 'instancemethod' object has no attribute '_fixture_type'

Wut??
So I went inside tests directory:

$ cd tests
$ testify
Usage: testify <test path> [options]

testify: error: Test path required unless --connect specified.
$ testify .
DISCOVERY FAILURE!
There was a problem importing one or more tests:
Failed to find module .

No tests were discovered (tests must subclass TestCase and test methods must begin with 'test').
ERROR.  0 tests / 0 cases: 0 passed, 0 failed.  (Total test time 0.00s)
$ testify test_baker.py
DISCOVERY FAILURE!
There was a problem importing one or more tests:
Failed to find module test_baker.py

No tests were discovered (tests must subclass TestCase and test methods must begin with 'test').
ERROR.  0 tests / 0 cases: 0 passed, 0 failed.  (Total test time 0.00s)
$ testify test_baker
DISCOVERY FAILURE!
There was a problem importing one or more tests:
Failed to find module test_baker

No tests were discovered (tests must subclass TestCase and test methods must begin with 'test').
ERROR.  0 tests / 0 cases: 0 passed, 0 failed.  (Total test time 0.00s)

Uhm, how do I run tests?

@EvanKrall
Member

You almost certainly want to be running tests from the root folder of your project, so don't cd tests -- that wreaks havoc with python's import.

As for your original problem, we just made some changes to the base TestCase class. What version of Testify are you running?

@rubik
Contributor
rubik commented Jun 27, 2012

Ok, I understand. I'm running PyPI one. Now I'll clone the repo and try that one instead.

@EvanKrall
Member

How are things going? Still having issues? I suspect running from a clone of master wouldn't help; it looks like Pypi is up to date, so they should be the same code. However, if you check out 0.2.10, you might have a different outcome.

@rubik
Contributor
rubik commented Jun 27, 2012

Yes, it gives the very same error... I'll checkout 0.2.10.

@rubik
Contributor
rubik commented Jun 27, 2012

Yes it works as expected. So it's a problem in 0.3 and thus in PyPI version too (as they're the same).

@EvanKrall
Member

Okay, thanks.

It's getting late here (1am) but we'll take a look in the morning.

@rubik
Contributor
rubik commented Jun 27, 2012

The error makes no sense. It is setting an attribute, not getting it, so why that error??
I found something similar here:
http://stackoverflow.com/questions/7034063/adding-attributes-to-instancemethods-in-python

I'm going to git bisect to find the commit that introduced the error...

@rubik
Contributor
rubik commented Jun 27, 2012

9202105 is the first bad commit

@ayust
Contributor
ayust commented Jun 27, 2012

For the record, what Python version are you running (python --version)?

I see that you're in a 2.7 directory path, but minor version would be helpful too - I haven't managed to reproduce this on 2.7.1.

@ayust
Contributor
ayust commented Jun 27, 2012

Okay, looks like it reproduces on Python 2.7.3.

@rubik
Contributor
rubik commented Jun 27, 2012

Yes 2.7.3

@rubik
Contributor
rubik commented Jun 27, 2012

Solved. Add:

try:
    function = function.__func__
except AttributeError:
    pass  # On Python 3.x there's no __func__

before:

function._fixture_type = fixture_type

in test_case.py, line 557

In Python 3 methods are just normal functions, while in Python 2 they are not. So we need the func attribute...

@rubik
Contributor
rubik commented Jun 27, 2012

Shall I open a pull request?

@EvanKrall
Member

Yes please! We're always happy to have submissions from the community.

@rubik
Contributor
rubik commented Jun 27, 2012

I forked the repo and ready to commit but before I run tests. Is this normal?

$ testify test
ERROR    error: test.test_runner_test PluginTestCase.test_plugin_run
Traceback (most recent call last):
  File "./test/test_runner_test.py", line 48, in test_plugin_run
    runner = test_runner.TestRunner(self.dummy_test_class, plugin_modules=[self.our_module])
AttributeError: 'PluginTestCase' object has no attribute 'dummy_test_class'

EERROR    error: test.json_log_test JSONReporterTestCase.test_report_extended_test_module_name
Traceback (most recent call last):
  File "./test/json_log_test.py", line 75, in test_report_extended_test_module_name
    self.json_reporter.test_start(result.to_dict())
AttributeError: 'JSONReporterTestCase' object has no attribute 'json_reporter'

E..........ERROR    error: test.test_runner_server_test TestRunnerServerBrokenImportTestCase.test_reports_are_generated_after_discovery_failure
Traceback (most recent call last):
  File "./test/test_runner_server_test.py", line 118, in test_reports_are_generated_after_discovery_failure
    assert_equal(self.report_call_count, 1)
AttributeError: 'TestRunnerServerBrokenImportTestCase' object has no attribute 'report_call_count'

EERROR    error: test.test_runner_server_test TestRunnerServerTestCase.test_fail_then_timeout_twice
Traceback (most recent call last):
  File "./test/test_runner_server_test.py", line 185, in test_fail_then_timeout_twice
    first_test = get_test(self.server, 'runner1')
AttributeError: 'TestRunnerServerTestCase' object has no attribute 'server'

EERROR    error: test.test_runner_server_test TestRunnerServerTestCase.test_get_next_test_doesnt_loop_forever
Traceback (most recent call last):
  File "./test/test_runner_server_test.py", line 231, in test_get_next_test_doesnt_loop_forever
    self.server.test_queue = test_runner_server.AsyncDelayedQueue()
AttributeError: 'TestRunnerServerTestCase' object has no attribute 'server'

EERROR    error: test.test_runner_server_test TestRunnerServerTestCase.test_passing_tests_run_only_once
Traceback (most recent call last):
  File "./test/test_runner_server_test.py", line 136, in test_passing_tests_run_only_once
    first_test = get_test(self.server, 'runner1')
AttributeError: 'TestRunnerServerTestCase' object has no attribute 'server'

EERROR    error: test.test_runner_server_test TestRunnerServerTestCase.test_requeue_on_failure
Traceback (most recent call last):
  File "./test/test_runner_server_test.py", line 148, in test_requeue_on_failure
    first_test = get_test(self.server, 'runner1')
AttributeError: 'TestRunnerServerTestCase' object has no attribute 'server'

EERROR    error: test.test_runner_server_test TestRunnerServerTestCase.test_requeue_on_timeout
Traceback (most recent call last):
  File "./test/test_runner_server_test.py", line 165, in test_requeue_on_timeout
    first_test = get_test(self.server, 'runner1')
AttributeError: 'TestRunnerServerTestCase' object has no attribute 'server'

EERROR    error: test.test_runner_server_test TestRunnerServerTestCase.test_timeout_then_fail_twice
Traceback (most recent call last):
  File "./test/test_runner_server_test.py", line 207, in test_timeout_then_fail_twice
    first_test = get_test(self.server, 'runner1')
AttributeError: 'TestRunnerServerTestCase' object has no attribute 'server'

E.....ERROR    error: test.utils.test_turtle TurtleTestCase.test_attribute
Traceback (most recent call last):
  File "./test/utils/test_turtle.py", line 33, in test_attribute
    assert self.leonardo.is_awesome().and_can_chain().whatever_he_wants()
AttributeError: 'TurtleTestCase' object has no attribute 'leonardo'

EERROR    error: test.utils.test_turtle TurtleTestCase.test_attribute_persistence
Traceback (most recent call last):
  File "./test/utils/test_turtle.py", line 50, in test_attribute_persistence
    weapon = self.leonardo.weapon
AttributeError: 'TurtleTestCase' object has no attribute 'leonardo'

EERROR    error: test.utils.test_turtle TurtleTestCase.test_attribute_setting
Traceback (most recent call last):
  File "./test/utils/test_turtle.py", line 45, in test_attribute_setting
    self.leonardo.color = "blue"
AttributeError: 'TurtleTestCase' object has no attribute 'leonardo'

EERROR    error: test.utils.test_turtle TurtleTestCase.test_call
Traceback (most recent call last):
  File "./test/utils/test_turtle.py", line 25, in test_call
    ret = self.leonardo()
AttributeError: 'TurtleTestCase' object has no attribute 'leonardo'

EERROR    error: test.utils.test_turtle TurtleTestCase.test_call_record
Traceback (most recent call last):
  File "./test/utils/test_turtle.py", line 37, in test_call_record
    self.leonardo(1, 2, 3, quatro=4)
AttributeError: 'TurtleTestCase' object has no attribute 'leonardo'

EERROR    error: test.discovery_failure_test DiscoveryFailureTestCase.test_discover_test_with_broken_import
Traceback (most recent call last):
  File "./test/discovery_failure_test.py", line 53, in test_discover_test_with_broken_import
    discovered_tests = test_discovery.discover(self.broken_import_module)
AttributeError: 'DiscoveryFailureTestCase' object has no attribute 'broken_import_module'

EERROR    error: test.test_logger_test TestTextLoggerDiscoveryFailureTestCase.test_text_test_logger_prints_discovery_failure_message
Traceback (most recent call last):
  File "./test/test_logger_test.py", line 29, in test_text_test_logger_prints_discovery_failure_message
    self.broken_import_module,
AttributeError: 'TestTextLoggerDiscoveryFailureTestCase' object has no attribute 'broken_import_module'

E.............ERROR    error: test.test_case_test ClassSetupFixturesGetRun.test_test_var
Traceback (most recent call last):
  File "./test/test_case_test.py", line 81, in test_test_var
    assert self.test_var
AttributeError: 'ClassSetupFixturesGetRun' object has no attribute 'test_var'

E..ERROR    error: test.test_case_test DeprecatedFixtureOrderTestChild.test_something
Traceback (most recent call last):
  File "./test/test_case_test.py", line 447, in classSetUp
    assert self.something == True
AttributeError: 'DeprecatedFixtureOrderTestChild' object has no attribute 'something'

E...ERROR    error: test.test_case_test TestifiedDerivedUnitTestWithAdditionalFixturesAndTests.test_foo_bar_baz
Traceback (most recent call last):
  File "./test/test_case_test.py", line 421, in test_foo_bar_baz
    assert self.bar
AttributeError: 'TestifiedDerivedUnitTestWithAdditionalFixturesAndT' object has no attribute 'bar'

EERROR    error: test.test_case_test TestifiedDerivedUnitTestWithFixturesAndTests.test_foo_bar
Traceback (most recent call last):
  File "./test/test_case_test.py", line 404, in test_foo_bar
    assert self.bar
AttributeError: 'TestifiedDerivedUnitTestWithFixturesAndTests' object has no attribute 'bar'

EERROR    fail: test.test_case_test FixtureMethodRegistrationOrderTest.test_fixture_registration_order
Traceback (most recent call last):
  File "./test/test_case_test.py", line 224, in test_fixture_registration_order
    assert_equal(self.counter, 10)
AssertionError: assertion failed: l == r
l: 0
r: 10

Diff:
l: <>0
r: <1>0

F.......ERROR    error: test.test_case_test SetupFixturesGetRun.test_test_var
Traceback (most recent call last):
  File "./test/test_case_test.py", line 90, in test_test_var
    assert self.test_var
AttributeError: 'SetupFixturesGetRun' object has no attribute 'test_var'

E.ERROR    error: test.test_case_test TeardownFixturesGetRun.test_test_var_second_pass
Traceback (most recent call last):
  File "./test/test_case_test.py", line 108, in test_test_var_second_pass
    assert self.test_var
AttributeError: 'TeardownFixturesGetRun' object has no attribute 'test_var'

E.ERROR    error: test.test_case_test TestFixtureMixinOrder.test_bar
Traceback (most recent call last):
  File "./test/test_case_test.py", line 310, in test_bar
    self.bar_ran = self.bar
AttributeError: 'TestFixtureMixinOrder' object has no attribute 'bar'

EERROR    error: test.test_case_test TestFixtureMixinOrder.test_foo
Traceback (most recent call last):
  File "./test/test_case_test.py", line 283, in test_foo
    self.foo_ran = self.get_foo
  File "./test/test_case_test.py", line 280, in get_foo
    return self.foo
AttributeError: 'TestFixtureMixinOrder' object has no attribute 'foo'

EERROR    error: test.test_case_test TestFixtureMixinsGetRun.test_foo
Traceback (most recent call last):
  File "./test/test_case_test.py", line 283, in test_foo
    self.foo_ran = self.get_foo
  File "./test/test_case_test.py", line 280, in get_foo
    return self.foo
AttributeError: 'TestFixtureMixinsGetRun' object has no attribute 'foo'

E..ERROR    error: test.test_case_test TestOtherCasesWithSameFixtureMixinsGetRun.test_foo
Traceback (most recent call last):
  File "./test/test_case_test.py", line 283, in test_foo
    self.foo_ran = self.get_foo
  File "./test/test_case_test.py", line 280, in get_foo
    return self.foo
AttributeError: 'TestOtherCasesWithSameFixtureMixinsGetRun' object has no attribute 'foo'

EERROR    error: test.test_case_test TestRegisterFixtureMethodsChildClass.test_things_exist
Traceback (most recent call last):
  File "./test/test_case_test.py", line 138, in test_things_exist
    self.failUnless(self.parent_setup_exists == 2)
AttributeError: 'TestRegisterFixtureMethodsChildClass' object has no attribute 'parent_setup_exists'

EERROR    error: test.test_case_test TestSubclassedCasesWithFeatureMixinsGetRun.test_foo
Traceback (most recent call last):
  File "./test/test_case_test.py", line 283, in test_foo
    self.foo_ran = self.get_foo
  File "./test/test_case_test.py", line 280, in get_foo
    return self.foo
AttributeError: 'TestSubclassedCasesWithFeatureMixinsGetRun' object has no attribute 'foo'

E.ERROR    fail: test.test_case_test UnitTestTestYoDawg.test_unit_test_status
Traceback (most recent call last):
  File "./test/test_case_test.py", line 355, in test_unit_test_status
    assert UnitTest.status == [True] * 6, UnitTest.status
AssertionError: [True, True, True, True, True, False]

FERROR    error: test.plugins.http_reporter_test HTTPReporterTestCase.test_http_reporter_reports
Traceback (most recent call last):
  File "./test/plugins/http_reporter_test.py", line 66, in test_http_reporter_reports
    runner = TestRunner(DummyTestCase, test_reporters=[HTTPReporter(None, self.connect_addr, 'runner1')])
AttributeError: 'HTTPReporterTestCase' object has no attribute 'connect_addr'

EERROR    error: test.plugins.http_reporter_test HTTPReporterTestCase.test_http_reporter_tries_twice
Traceback (most recent call last):
  File "./test/plugins/http_reporter_test.py", line 75, in test_http_reporter_tries_twice
    self.status_codes.put(409)
AttributeError: 'HTTPReporterTestCase' object has no attribute 'status_codes'

EERROR    error: test.plugins.sql_reporter_test SQLReporterDiscoveryFailureTestCase.test_sql_reporter_sets_discovery_failure_flag
Traceback (most recent call last):
  File "./test/plugins/sql_reporter_test.py", line 154, in test_sql_reporter_sets_discovery_failure_flag
    runner = TestRunner(self.broken_import_module, test_reporters=[self.reporter])
AttributeError: 'SQLReporterDiscoveryFailureTestCase' object has no attribute 'broken_import_module'

EERROR    error: test.plugins.sql_reporter_test SQLReporterTestCase.test_integration
Traceback (most recent call last):
  File "./test/plugins/sql_reporter_test.py", line 61, in test_integration
    runner = TestRunner(DummyTestCase, test_reporters=[self.reporter])
AttributeError: 'SQLReporterTestCase' object has no attribute 'reporter'

EERROR    error: test.plugins.sql_reporter_test SQLReporterTestCase.test_previous_run
Traceback (most recent call last):
  File "./test/plugins/sql_reporter_test.py", line 122, in test_previous_run
    conn = self.reporter.conn
AttributeError: 'SQLReporterTestCase' object has no attribute 'reporter'

EERROR    error: test.plugins.sql_reporter_test SQLReporterTestCase.test_update_counts
Traceback (most recent call last):
  File "./test/plugins/sql_reporter_test.py", line 109, in test_update_counts
    conn = self.reporter.conn
AttributeError: 'SQLReporterTestCase' object has no attribute 'reporter'

E
FAILED.  81 tests / 48 cases: 45 passed, 36 failed.  (Total test time 0.02s)

Before making the change I could not run tests so I cannot compare with the previous one...

@ayust
Contributor
ayust commented Jun 27, 2012

No, that's not normal - all tests should pass.

@blampe
Contributor
blampe commented Jun 27, 2012

It looks like setup fixtures aren't running with that patch. I get the same failures and I'm also playing around with it.

@blampe
Contributor
blampe commented Jun 27, 2012

I have a working fix and am just testing and cleaning it up. Should have a pull request shortly.

@rubik
Contributor
rubik commented Jun 27, 2012

Great! I will open a pull request after yours get accepted then.

@rubik rubik closed this Jun 27, 2012
@rubik rubik reopened this Jun 27, 2012
@rubik
Contributor
rubik commented Jun 27, 2012

Sorry wrong button.

@ayust
Contributor
ayust commented Jun 27, 2012

@rubik Bryce's fix has been merged; it should resolve this issue as well. Can you test?

(I've verified that it fixes the issue on my Python 2.7.3 install.)

@rubik
Contributor
rubik commented Jun 28, 2012

I confirm: now all tests passes on Python 2.7.3

@rubik rubik closed this Jun 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment