Created
November 24, 2014 15:29
-
-
Save edisongustavo/5533a1c36de6cab6f39a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
class ValueAndString(object): | |
def __init__(self, value, string): | |
self.value = value | |
self.string = string | |
if type(string) != unicode: | |
raise ValueError('Error!') | |
def __eq__(self, other): | |
return self.value == other.value and self.string == other.string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
import pytest | |
from classes import ValueAndString | |
pytest_plugins = [ | |
b'plugin_fixture' | |
] | |
class ConftestFixture(object): | |
def foo(self): | |
assert ValueAndString(1, 'lkajflaskjfalskf') == ValueAndString(2, 'lkajflaskjfalskf') | |
@pytest.fixture | |
def conftest_fixture(): | |
return ConftestFixture() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
import pytest | |
from classes import ValueAndString | |
class PluginFixture(object): | |
def foo(self): | |
assert ValueAndString(2, 'lkajflaskjfalskf') == ValueAndString(1, 'lkajflaskjfalskf') | |
@pytest.fixture | |
def plugin_fixture(): | |
return PluginFixture() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
import sys | |
from py._code.code import Frame | |
def foo(): | |
previous_frame = Frame(sys._getframe(-1)) | |
foo_string = previous_frame.eval("'foo'") | |
print type(foo_string) # should be 'unicode', but it is 'str' | |
def main(): | |
foo() | |
if __name__ == '__main__': | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
import pytest | |
from classes import ValueAndString | |
class InlineFixture(object): | |
def foo(self): | |
assert ValueAndString(2, 'lkajflaskjfalskf') == ValueAndString(1, 'lkajflaskjfalskf') | |
@pytest.fixture | |
def inline_fixture(): | |
return InlineFixture() | |
def test_plugin_fixture(plugin_fixture): | |
with pytest.raises(AssertionError) as e: | |
plugin_fixture.foo() | |
msg = e.value.msg | |
assert msg.startswith('assert <classes.ValueAndString object'), msg | |
def test_conftest_fixture(conftest_fixture): | |
with pytest.raises(AssertionError) as e: | |
conftest_fixture.foo() | |
msg = e.value.msg | |
assert msg.startswith('assert <classes.ValueAndString object'), msg | |
def test_inline_fixture(inline_fixture): | |
with pytest.raises(AssertionError) as e: | |
inline_fixture.foo() | |
msg = e.value.msg | |
assert msg.startswith('assert <classes.ValueAndString object'), msg | |
def test_no_fixture(): | |
with pytest.raises(AssertionError) as e: | |
assert ValueAndString(1, 'lkajflaskjfalskf') == ValueAndString(2, 'lkajflaskjfalskf') | |
msg = e.value.msg | |
assert msg.startswith('assert <classes.ValueAndString object'), msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment