コード例 #1
0
#!/usr/bin/env python
from __future__ import print_function, division, absolute_import
import os
import inspect
import pytest_helper
import set_package_attribute

if __name__ == "__main__":
    #pytest_helper.init(set_package=True) # Finds no tests when this is set!
    pytest_helper.init()
    import sys
    #pytest_helper.script_run(self_test=True)
    pytest_helper.script_run(self_test="test_in_package_subdir", pyargs=True)

pytest_helper.sys_path("../../..")
from package_dir.package_subdir import subdir_dummy_module

pytest_helper.autoimport()
def test_running_test_in_package_subdir():
    assert True

コード例 #2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""

A test file run from a child test directory, with no __init__.py file.
The file being tested is in the parent dir.

"""

from __future__ import print_function, division, absolute_import
import pytest_helper
from pytest_helper import PytestHelperException, LocalsToGlobalsError
pytest_helper.init() # Needed because of testing chdir call inserted below.

import os
old_cwd = os.getcwd()
os.chdir("..") # Causes an error if pytest_helper.init() is not called above.

pytest_helper.script_run(self_test=True, pytest_args="-v -s")
# More efficient to put below two lines after script_run (won't run twice).
pytest_helper.autoimport()

# The module to be tested is in_child_dir.
# The import below defines test_string="in_child_dir".
pytest_helper.sys_path(add_grandparent=True)
from package_dir.in_child_dir import *  # Note imported as a package module.
#pytest_helper.sys_path(add_parent=True)
#from in_child_dir import *  # Note imported as a regular module, NOT a package module.

os.chdir(old_cwd) # Return to prev dir so as not to mess up later tests.
コード例 #3
0
ファイル: in_same_dir.py プロジェクト: abarker/pytest-helper
#!/usr/bin/env python
"""

This module is tested by a test file in the same directory, inside the package.

The `script_run` call is near the bottom of the file, even though that is
not recommended, to test for and try to avoid potential problems.

"""

from __future__ import print_function, division, absolute_import
import os
import inspect
import pytest_helper
pytest_helper.init(set_package=True)

# This import *needs* the init with the set_package above in order to work.
# Would NOT be needed, though, with script_run run from top of the file
# as recommended instead of after the import.
from . import dummy_module

# This line is all this module really does; obviously a real, non-test module
# would do more.
test_string = "in_same_dir"

##
## Run tests.
##

# Below imports both work, but commented out to not confound tests.
#import package_dir.test_in_same_dir
コード例 #4
0
ファイル: in_same_dir.py プロジェクト: abarker/pytest-helper
#!/usr/bin/env python
"""

This module is tested by a test file in the same directory, inside the package.

The `script_run` call is near the bottom of the file, even though that is
not recommended, to test for and try to avoid potential problems.

"""

from __future__ import print_function, division, absolute_import
import os
import inspect
import pytest_helper
pytest_helper.init(set_package=True)

# This import *needs* the init with the set_package above in order to work.
# Would NOT be needed, though, with script_run run from top of the file 
# as recommended instead of after the import.
from . import dummy_module

# This line is all this module really does; obviously a real, non-test module
# would do more.
test_string = "in_same_dir"

##
## Run tests.
##

# Below imports both work, but commented out to not confound tests.
#import package_dir.test_in_same_dir
コード例 #5
0
#!/usr/bin/env python
from __future__ import print_function, division, absolute_import
import os
import inspect
import pytest_helper
import set_package_attribute

if __name__ == "__main__":
    #pytest_helper.init(set_package=True) # Finds no tests when this is set!
    pytest_helper.init()
    import sys
    #pytest_helper.script_run(self_test=True)
    pytest_helper.script_run(self_test="test_in_package_subdir", pyargs=True)

pytest_helper.sys_path("../../..")
from package_dir.package_subdir import subdir_dummy_module

pytest_helper.autoimport()


def test_running_test_in_package_subdir():
    assert True
コード例 #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""

A test file run from a child test directory, with no __init__.py file.
The file being tested is in the parent dir.

"""

from __future__ import print_function, division, absolute_import
import pytest_helper
from pytest_helper import PytestHelperException, LocalsToGlobalsError

pytest_helper.init()  # Needed because of testing chdir call inserted below.

import os

old_cwd = os.getcwd()
os.chdir("..")  # Causes an error if pytest_helper.init() is not called above.

pytest_helper.script_run(self_test=True, pytest_args="-v -s")
# More efficient to put below two lines after script_run (won't run twice).
pytest_helper.autoimport()

# The module to be tested is in_child_dir.
# The import below defines test_string="in_child_dir".
pytest_helper.sys_path(add_grandparent=True)
from package_dir.in_child_dir import *  # Note imported as a package module.
#pytest_helper.sys_path(add_parent=True)
#from in_child_dir import *  # Note imported as a regular module, NOT a package module.
コード例 #7
0
"""

"""

from __future__ import print_function, division, absolute_import
import pytest_helper
pytest_helper.init(conf=False)

testing_var = "foo"

if __name__ == "__main__":
    pytest_helper.script_run(self_test=True, pytest_args="-v")

pytest_helper.autoimport()

def test_config_values():
    assert testing_var == "foo"
    clear_locals_from_globals() # Call this before locals_to_globals, make sure it works.
    locals_to_globals()

    # This is on the autoimport skip list in disabled ini file.
    # It should work with config files disabled.
    clear_locals_from_globals()

コード例 #8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
import pytest_helper
from pytest_helper import PytestHelperException, LocalsToGlobalsError

pytest_helper.init()  # Needed because testing with a chdir call, inserted below.

import os

old_cwd = os.getcwd()
os.chdir("..")  # Causes an error if pytest_helper.init() is not called above.

pytest_helper.script_run(self_test=True, pytest_args="-v -s")
# More efficient to put below two lines after script_run (won't run twice).
pytest_helper.sys_path(["../package_dir"])
pytest_helper.autoimport()

# The module to be tested is in_sibling_dir.
# The import below defines test_string="in_sibling_dir".
from in_sibling_dir import *

os.chdir(old_cwd)  # Return to prev dir so as not to mess up later tests.


@fixture
def basic_setup():
    teststr = "tree"
    teststr2 = "rock"
    # Normally you'd only call locals_to_globals at the end of setup funs, like here.
    locals_to_globals()
コード例 #9
0
"""

"""

from __future__ import print_function, division, absolute_import
import pytest_helper
pytest_helper.init(conf=False)

testing_var = "foo"

if __name__ == "__main__":
    pytest_helper.script_run(self_test=True, pytest_args="-v")

pytest_helper.autoimport()


def test_config_values():
    assert testing_var == "foo"
    clear_locals_from_globals(
    )  # Call this before locals_to_globals, make sure it works.
    locals_to_globals()

    # This is on the autoimport skip list in disabled ini file.
    # It should work with config files disabled.
    clear_locals_from_globals()
コード例 #10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
import pytest_helper
from pytest_helper import PytestHelperException, LocalsToGlobalsError
pytest_helper.init() # Needed because testing with a chdir call, inserted below.

import os
old_cwd = os.getcwd()
os.chdir("..") # Causes an error if pytest_helper.init() is not called above.

pytest_helper.script_run(self_test=True, pytest_args="-v -s")
# More efficient to put below two lines after script_run (won't run twice).
pytest_helper.sys_path(["../package_dir"])
pytest_helper.autoimport()

# The module to be tested is in_sibling_dir.
# The import below defines test_string="in_sibling_dir".
from in_sibling_dir import *

os.chdir(old_cwd) # Return to prev dir so as not to mess up later tests.

@fixture
def basic_setup():
    teststr = "tree"
    teststr2 = "rock"
    # Normally you'd only call locals_to_globals at the end of setup funs, like here.
    locals_to_globals()

def test_basic_stuff(basic_setup):
    assert test_string == "in_sibling_dir" # This is set as a global in in_sibling_dir.