Skip to content

Performance optimizations#13

Open
johntemyra wants to merge 1 commit intotexttest:masterfrom
johntemyra:jory/performance_optimizations
Open

Performance optimizations#13
johntemyra wants to merge 1 commit intotexttest:masterfrom
johntemyra:jory/performance_optimizations

Conversation

@johntemyra
Copy link

recordfilehandler: write to a buffered file which is kept open throughout its lifetime
capturepython: switch from using inspect.stack() to sys._getframe()

@johntemyra
Copy link
Author

I've tested the python_attributes tests and they are ok except for an empty file which is created for one of the tests.
Can't get the tests that uses the capturemock binary to run.
Need some instructions/hints on how to make them run.

@gjb1002
Copy link
Contributor

gjb1002 commented Jan 28, 2026

I fetched the branch and ran the tests (on Windows). Most of them fail for me.
python_attributes tests mostly raise an exception [WinError 32] The process cannot access the file because it is being used by another process:. Suspect this error may be specific to Windows, don't think Linux cares about such things...

server-based tests generally raise an exception: ValueError: I/O operation on closed file.
So something seems a bit wrong with recordfilehandler.py. Haven't yet looked at the code.

@gjb1002
Copy link
Contributor

gjb1002 commented Jan 28, 2026

I will be working at home tomorrow though, so can probably test this on Linux there then.

@johntemyra
Copy link
Author

johntemyra commented Jan 28, 2026

Now I also checked on windows tests. Turns out that windows can't close open files but linux can... Didn't know that.
I pushed a fix for the unclosed files but I still get some failed tests in the python_attributes test cases (functional and exceptions).
There are files and folders created that shouldn't and also more concerning, is that some of the replayed files are messed up.
I need to take a closer look on why that is.

When I try to run other tests than the python_attributes I get this error:
image
Same as on linux (but without the exe). I don't know where I would get the binary from other than building it (from the same source) but that fails the tests miserably.

@gjb1002
Copy link
Contributor

gjb1002 commented Jan 29, 2026

That error looks like you're pointing out your source code checkout. You need to point "use checkout" (or -c on the command line) to the virtual environment where you've installed capturemock, also on Linux. When you install it should create capturemock.exe on Windows. No need to build anything.

I ran the tests on my Ubuntu laptop now. A handful of failures - it's been quite a while since I ran these tests on Linux! A few tests have external dependencies and are fixed by installing "pyftpdlib" and "opcua" with pip, some more have filtering issues which I will fix. Leaves 2 that are failing for unknown reasons, but both are quite specific functionality that probably isn't relevant to you.

@gjb1002
Copy link
Contributor

gjb1002 commented Jan 29, 2026

Fixed the filtering issues in my above comment now. Should only be 2 red tests on clean Linux now, after installing the listed modules.

@johntemyra
Copy link
Author

That sounds promising when you put it like that. The differences in capturemock files looks ominous though. Thanks for looking into the issues and of course that you take the time to respond so quickly.
I'll see if I can take a look at it later today.
Have you tried running the tests on windows also? Did you get the same errors there (after the last commit)?

@gjb1002
Copy link
Contributor

gjb1002 commented Jan 29, 2026

I haven't tried to run your branch on Linux yet. My comments re: Linux were based on running the latest code in master.

I got your latest change on Windows, only one failure for me under python_attributes now, the test "socket_module_unused". Server-based tests are still all failing in the same way as I mentioned before.

@johntemyra
Copy link
Author

johntemyra commented Jan 29, 2026

Ah! Ok, I understand, it was the tests without the change that you described. I'll see if I can get the server based texts going and fix the failing ones with the change.

@johntemyra
Copy link
Author

johntemyra commented Feb 2, 2026

Did you solve the permission error on windows?

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\jory\Work\python311_venv\Scripts\capturemock.exe\__main__.py", line 7, in <module>
  File "C:\Users\jory\Work\Dev\capturemock_fork\capturemock\__init__.py", line 228, in commandline
    shutil.rmtree(interceptDir)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\shutil.py", line 787, in rmtree
    return _rmtree_unsafe(path, onerror)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\shutil.py", line 634, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\shutil.py", line 632, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: '<sandbox>\\tmpk1_8fql3\\firstcall.exe'

I get a lot of this even though I'm using your latest changes in capturemock and capturemock_selftest. I think I have some environment issues I need to solve before I can test my branch...

image

I'm using:

texttest 4.4.6
capturemock (commit b4c8c43fd724631d1e9b3efed1763680533ad3b6)
capturemock_selftest (commit 1d5c988836488e07a2b5c69340af4c7ca3a3d73f)

@gjb1002
Copy link
Contributor

gjb1002 commented Feb 3, 2026

I have the latest of everything too, I don't get these issues on Windows, everything is green for me.

Only difference I can see is that I'm using Python 3.13 rather than Python 3.11.

Looks like temporary .exe files that aren't terminating when they should. Some firewall/antivirus something interfering? Don't know.

The client_server failures are the two libraries I mentioned earlier, just install pyftpdlib and opcua in your virtual environment and they should be green.

recordfilehandler: write to a buffered file which is kept open throughout its lifetime
capturepython: switch from using inspect.stack() to sys._getframe()
@johntemyra johntemyra force-pushed the jory/performance_optimizations branch from 86d82bb to e2d437f Compare February 3, 2026 21:12
@johntemyra
Copy link
Author

I got a bit further now with the tests on my branch.

Now all the tests, but the opcua and ftp are running green on windows.
Python environments is a mess. Somehow the tests still complain that opcua can't be found even though I've installed it...

The python_attributes tests did run OK on linux but the environment is a mess there too so the other tests complained "no such file or directory: 'python'" 🙄

It's getting late so I'll give up for today.

@gjb1002
Copy link
Contributor

gjb1002 commented Feb 4, 2026

Somehow the tests still complain that opcua can't be found even though I've installed it...

Sounds very strange. You might want to test/investigate outside TextTest.

so the other tests complained "no such file or directory: 'python'"

Hmm, maybe the executable is called "python3" on your Linux? Not sure.

@johntemyra
Copy link
Author

Hi again,

I've tried running the tests again but struggling with the same issues. I've tried configuring the test suites in the capturemock-selftest config files but to no avail.

Here's a screenshot from a failed test when run on linux.

image

The windows tests still runs OK for me, except for the opcua and ftp tests.

I am using a python venv-environment. Maybe that is not intended for texttests??

If it is not too much to ask; could you do me a favor and run the the branch in your environments (windows and linux) to see if the the tests runs OK?

If you don't have the time or oppertunity to do so I totally understand and I will try some more to get it to work here.

Kind regards
John

@gjb1002
Copy link
Contributor

gjb1002 commented Feb 16, 2026

Just ran your latest branch on Windows. Everything is green except the ftp tests, which seems to be a straightforward error. Can you try installing the two modules I mentioned before in your venv on Windows and see if you can reproduce and fix this?

I will run it on my Ubuntu laptop at home when I get time, might not be for a few days.

Not sure why can you can't run the tests on Linux. It seems to be failing to start its own server because "python" isn't recognised as an executable. This should have come from the getPython() method, which should be sys.executable on Linux, which should be an absolute path. Maybe you can add a debug printout there to see what's going on?

@gjb1002
Copy link
Contributor

gjb1002 commented Feb 17, 2026

Ran your branch on Linux now. Same failures on the ftp tests as Windows, plus the two tests that also fail on master for me. Otherwise green.

@gjb1002
Copy link
Contributor

gjb1002 commented Feb 17, 2026

Also discovered that I had added my virtual environment's bin directory to my PATH via .bashrc at some point in the long-forgotten past, which was the reason the tests were working for me on Linux now. When I removed this I reproduced the error you get.

So that should both allow me to investigate and you to work around it!

@gjb1002
Copy link
Contributor

gjb1002 commented Feb 17, 2026

Linux tests mostly working again after doing sudo apt install python-is-python3.

Execeptions being opcua and ftp again - you need to install those libraries globally rather than in the virtual environment currently. Or create a different venv, install them there, and add it to your PATH as above.

@johntemyra
Copy link
Author

johntemyra commented Feb 17, 2026 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants