2017-06-15 32 views
0
import unittest 
import HtmlTestRunner 
import os 
from Ultimatix_login import ultimatix_login1 
from searchtest import searchtest 

directory1=os.getcwd() 
class main_test(unittest.TestCase): 
    def test_Issue(self): 
     test1=unittest.TestLoader().loadTestsFromTestCase(ultimatix_login1) 
     tests2=unittest.TestLoader().loadTestsFromTestCase(searchtest) 
#combining both the test cases into one suite 
     suite=unittest.TestSuite([test1,tests2]) 
     outfile=open(directory1,"\maintest.html","w") 
     runner1=HtmlTestRunner.HTMLTestRunner(
      output=outfile, 
      report_title="test_report", 
      descriptions="Main_test" 
      ) 
     runner1.run(suite) 

#opening the report file 
#outfile=open(dir +"\testreport.html","w") 

if __name__=="__main__": 
    unittest.main() 

我試圖生成html檢測報告,但測試案例正確執行,但HTML報表不產生請幫助我走出這個.. 謝謝。類型錯誤:一個整數需要(有型STR)在python硒webdri

+0

哪條線是給你的錯誤?錯誤本身意味着你給一個字符串作爲一個函數的輸入,而不是一個整數。請注意,您可能會給出類似「1」的東西,而不是1.在這種情況下,您可以使用int(strin_to_be_casted) – FrAxl93

回答

0

這一行是不正確的:

outfile=open(directory1,"\maintest.html","w") 

按照,其前三個參數預計是

  1. 文件路徑(字符串)
  2. 模式其中文件打開(字符串)
  3. 緩衝策略(整數)

要調用的函數,你傳遞以下參數的方法:

  1. 文件路徑directory1
  2. 模式"\maintest.html"
  3. 緩衝"w" - 這是錯誤的,應該是一個整數。

看來你實際上想使用<directory1>\maintest.html作爲文件路徑,而"w"作爲開放模式。

爲了做到這一點,使用os.path.join功能:(請注意,您必須忽略\,這無論如何都會意味着something different

outfile = open(os.path.join(directory1, "maintest.html"), "w") 

+0

來投射int。謝謝mkrieger1它現在正在工作,但仍顯示錯誤,如** TypeError:join()參數必須是str或字節,而不是'TextIOWrapper'**,請您檢查一次。 –

+0

** EC:\ ProgramData \ Anaconda3 \ lib \ unittest \ case.py:629:ResourceWarning:未關閉的文件<_io.TextIOWrapper **這個錯誤提示請幫我解決這個問題。 –

+0

我現在不知道是什麼導致了這個錯誤。你將不得不自己做一些調試。請參閱https://ericlippert.com/2014/03/05/how-to-debug-small-programs/ – mkrieger1

相關問題