Problem
As part of the python unittest, you need to load some input json files that exist in the "data" directory, which is located in the same folder of the py test file.
'pkg_resources' is used for this purpose.
It works great when unittest works with python. But it does not work at startup using a twisted process.
My project has mixed test tables with python unittest test packages, as well as twisted.trial.unittest test tests. therefore, there is a need to run both types of test boxes with twisted cork in general.
The directory '_trial_temp' is added to the path when running test files using a twisted trial version. please let me know if there is a way to handle this?
Example directory structure:
myproject/ βββ tests βββ data β βββ input.json βββ trialTest.py
trialTest.py
import unittest import inspect import pkg_resources class Test(unittest.TestCase): def test_01_pathTest(self): dataDirExists = pkg_resources.resource_exists(inspect.getmodule(self).__name__, 'data') print 'data exists: %s' % (dataDirExists) if __name__ == '__main__': unittest.main()
Running a test using python and outputting it:
cd myproject python tests/trialTest.py data exists: True . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK
Running a test using python and outputting it:
cd myproject /usr/local/bin/trial tests/trialTest.py trialTest Test test_01_pathTest ... data exists: False [OK] ------------------------------------------------------------------------------- Ran 1 tests in 0.013s PASSED (successes=1)
source share