4

I am using BrowserStack to run Selenium scripts in Python. Keep in mind that I am new in Python, so maybe there is a simple solution to this that I am not seeing.

You can see the code here

When I run it, it always shows the following: PyCharm dump

How to I solve the "ResourceWarning: Enable tracemalloc to get the object allocation traceback" error? Do I need to install some package, enable something in the settings, or..? The tests always execute, as you can see at the bottom, but these Warnings always appear.

Vedran Korponajić
  • 117
  • 1
  • 3
  • 8

2 Answers2

7

As mentioned in here!

This ResourceWarning means that you opened a file, used it, but then forgot to close the file. Python closes it for you when it notices that the file object is dead, but this only occurs after some unknown time has elapsed. Thus in recent versions, Python also prints a ResourceWarning when it does that.

Berraz.red
  • 71
  • 2
2

The tracemalloc module is a debug tool to trace memory blocks allocated by Python. You may refer to this for more details: https://docs.python.org/3/library/tracemalloc.html

Hence it is just a warning which is asking you to enable tracemalloc and not an error. This won't affect your test case.

  • From the link: to *enable tracemalloc* as the warning message mentioned (however, in this case it's usually only useful if it comes from your code and not library code), "[set] the PYTHONTRACEMALLOC environment variable to 1, or [use] -X tracemalloc command line option." Read the link for more details. – user202729 Dec 21 '20 at 06:18
  • The issue many users will have is that the leak is occurring in selenium libraries, so we are unqualified to resolve it ourselves, and also have no way of knowing if the leak is a false alarm because of the way the driver handles resources or caches. – Conrad B Feb 02 '21 at 14:21